当我使用Java 8 Stream.of原始类型时,结果很混乱 [英] when i use Java 8 Stream.of primitive type, the result is confused
本文介绍了当我使用Java 8 Stream.of原始类型时,结果很混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
byte[] a = {1,2,3};
System.out.println(Stream.of(a).count());
Byte[] b = {1,2,3};
System.out.println(Stream.of(b).count());
结果是1和3,为什么?
the result is 1 and 3, why?
推荐答案
Stream.of
仅接受对象作为其参数。 字节
不是Object,而是 byte
数组。如果 a
是一个 byte
的数组,那么 Stream.of(a)
只能表示这个对象的流,这是一个数组。
Stream.of
only accepts Objects as its arguments. A byte
isn't an Object, but a byte
array is. If a
is an array of byte
, then Stream.of(a)
can only mean "stream of this one object, which is an array".
如果你有一个 Byte []
数组,然后数组的每个元素都是一个对象,所以编译器可以猜到你的意思。
If you have a Byte[]
array, then each element of the array is an object, so the compiler can guess that's what you mean.
这里有关于你如何能有的信息流式字节数组:
在Java 8中,有没有ByteStream类?
There is information here about how you can stream a byte array: In Java 8, is there a ByteStream class?
这篇关于当我使用Java 8 Stream.of原始类型时,结果很混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文