程序设计

专业和发烧友程序员的问答


9
为什么Stream <T>不实现Iterable <T>?
在Java 8中,我们有类Stream &lt;T&gt;,它奇怪地有一个方法 Iterator&lt;T&gt; iterator() 因此,您可能希望它实现接口Iterable &lt;T&gt;,而该接口正是需要此方法,但事实并非如此。 当我想使用foreach循环遍历Stream时,我必须做类似的事情 public static Iterable&lt;T&gt; getIterable(Stream&lt;T&gt; s) { return new Iterable&lt;T&gt; { @Override public Iterator&lt;T&gt; iterator() { return s.iterator(); } }; } for (T element : getIterable(s)) { ... } 我在这里想念什么吗?

12
打印大型HTML表格时如何处理分页符
我有一个项目,要求打印带有许多行的HTML表格。 我的问题是表格在多页上的打印方式。有时它将切成两行,使其变得不可读,因为一半在页面的前沿,而其余部分则打印在下一页的顶部。 我能想到的唯一可行的解​​决方案是使用堆叠的DIV而不是表格,并在需要时强制分页。.但是在进行整个更改之前,我想我可以在这里问一下。
261 html  css  printing  html-table 

11
C#中字符串比较方法的差异
在C#中比较字符串非常简单。实际上,有几种方法可以做到这一点。我在下面的方框中列出了一些。我很好奇的是它们之间的区别以及何时应该使用它们之间的区别?应该不惜一切代价避免一个吗?我还没有列出更多吗? string testString = "Test"; string anotherString = "Another"; if (testString.CompareTo(anotherString) == 0) {} if (testString.Equals(anotherString)) {} if (testString == anotherString) {} (注意:我在此示例中寻求的是平等,不小于或大于但也可以对此发表评论)
261 c#  string  comparison 

4
为什么此后写的代码显示“ Hello World!”
这是我在Internet上找到的一些代码: class M‮{public static void main(String[]a‭){System.out.print(new char[] {'H','e','l','l','o',' ','W','o','r','l','d','!'});}} 此代码会打印Hello World!到屏幕上;您可以看到它在这里运行。我可以清楚地看到public static void main书面内容,但这是倒退的。该代码如何工作?怎么编译? 编辑:我在IntellIJ中尝试过此代码,并且工作正常。但是,由于某些原因,它不能与cmd一起在notepad ++中工作。我仍然没有找到解决方案,因此,如果有人这样做,请在下面进行评论。

7
具有位置参数的Git别名
基本上我想别名: git files 9fa3 ...执行命令: git diff --name-status 9fa3^ 9fa3 但是git似乎没有将位置参数传递给alias命令。我努力了: [alias] files = "!git diff --name-status $1^ $1" files = "!git diff --name-status {1}^ {1}" ...和其他一些,但没有用。 简并的情况是: $ git echo_reverse_these_params a b c d e e d c b a ...我该如何进行这项工作?

18
Android中的线性布局和权重
我总是在Android文档中读到这个有趣的体重值。现在,我想第一次尝试,但它根本没有用。 据我从文档中了解,此布局: &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"&gt; &lt;Button android:text="Register" android:id="@+id/register" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dip" weight="1" /&gt; &lt;Button android:text="Not this time" android:id="@+id/cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dip" weight="1" /&gt; &lt;/LinearLayout&gt; 应该创建两个水平对齐的按钮,并平均分配空间。问题在于这两个按钮没有增长来填充空间。 我希望按钮能够增长并填满整个生产线。如果两个按钮都设置为与父按钮匹配,则仅显示第一个按钮并填满整行。

7
Liquibase锁定-原因?
当对Oracle服务器运行许多liquibase脚本时,我得到了这个。SomeComputer是我。 Waiting for changelog lock.... Waiting for changelog lock.... Waiting for changelog lock.... Waiting for changelog lock.... Waiting for changelog lock.... Waiting for changelog lock.... Waiting for changelog lock.... Liquibase Update Failed: Could not acquire change log lock. Currently locked by SomeComputer (192.168.15.X) since 2013-03-20 13:39 SEVERE 2013-03-20 16:59:liquibase: Could …




11
为什么不能为.NET中的结构定义默认构造函数?
在.NET中,值类型(C#struct)不能具有没有参数的构造函数。根据这篇文章,这是CLI规范要求的。发生的情况是,对于每个值类型,都会创建一个默认的构造函数(由编译器生成?),该构造函数将所有成员初始化为零(或null)。 为什么不允许定义这样的默认构造函数? 琐碎的用途是有理数: public struct Rational { private long numerator; private long denominator; public Rational(long num, long denom) { /* Todo: Find GCD etc. */ } public Rational(long num) { numerator = num; denominator = 1; } public Rational() // This is not allowed { numerator = 0; denominator = …
261 c#  .net  struct 

30
显示动画GIF
我想在应用程序中显示GIF动画图像。正如我所发现的那样,Android本身并不支持GIF动画。 但是,它可以使用AnimationDrawable显示动画: 开发&gt;指南&gt;图像和图形&gt; Drawables概述 该示例使用在应用程序资源中另存为帧的动画,但是我需要直接显示动画gif。 我的计划是将动画GIF分解为帧,并将每个帧作为可绘制对象添加到AnimationDrawable中。 有谁知道如何从GIF动画中提取帧并将其转换为Drawable?


4
ReSharper警告:“通用类型的静态字段”
public class EnumRouteConstraint&lt;T&gt; : IRouteConstraint where T : struct { private static readonly Lazy&lt;HashSet&lt;string&gt;&gt; _enumNames; // &lt;-- static EnumRouteConstraint() { if (!typeof(T).IsEnum) { throw new ArgumentException( Resources.Error.EnumRouteConstraint.FormatWith(typeof(T).FullName)); } string[] names = Enum.GetNames(typeof(T)); _enumNames = new Lazy&lt;HashSet&lt;string&gt;&gt;(() =&gt; new HashSet&lt;string&gt; ( names.Select(name =&gt; name), StringComparer.InvariantCultureIgnoreCase )); } public bool Match(HttpContextBase httpContext, …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.