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());字节[] b = {1,2,3};System.out.println(Stream.of(b).count());结果是1和3,为什么?
Stream.of 只接受对象作为其参数.byte 不是 Object,但 byte 数组是.如果a是byte的数组,那么Stream.of(a)只能表示这个对象的流,是一个数组".
如果你有一个 Byte[] 数组,那么数组的每个元素都是一个对象,所以编译器可以猜到你的意思.
这里有关于如何流式传输字节数组的信息:在Java 8中,有ByteStream类吗?p>
byte[] a = {1,2,3};
System.out.println(Stream.of(a).count());
Byte[] b = {1,2,3};
System.out.println(Stream.of(b).count());
the result is 1 and 3, why?
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".
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.
There is information here about how you can stream a byte array: In Java 8, is there a ByteStream class?
这篇关于当我使用 Java 8 Stream.of 原始类型时,结果很混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当我使用 Java 8 Stream.of 原始类型时,结果很混乱
- 如何使用WebFilter实现授权头检查 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
