本文介绍了在 Java 8 中,是否有 ByteStream 类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 8 为 doubleintlong 提供了 Stream 特化:DoubleStreamIntStreamLongStream 分别.但是,我在 .

Java 8 provides Stream<T> specializations for double, int and long: DoubleStream, IntStream and LongStream respectively. However, I could not find an equivalent for byte in the documentation.

Java 8 是否提供 ByteStream 类?

Does Java 8 provide a ByteStream class?

推荐答案

不,它不存在.实际上,它并没有被明确实现,以免每个原始类型都有大量的类使 Stream API 变得混乱.

No, it does not exist. Actually, it was explicitly not implemented so as not to clutter the Stream API with tons of classes for every primitive type.

引用来自 Brian Goetz 的一封邮件在 OpenJDK 邮件列表中: 

Quoting a mail from Brian Goetz in the OpenJDK mailing list: 

简答:没有.

对于这些表单,每个 JDK 占用的空间都不值 100K+几乎从不使用.如果我们添加这些,有人会要求短、浮点数或布尔值.

It is not worth another 100K+ of JDK footprint each for these forms which are used almost never. And if we added those, someone would demand short, float, or boolean.

换句话说,如果人们坚持我们拥有所有原始专业化,我们将没有原始专业化.哪个会比现状更糟.

Put another way, if people insisted we had all the primitive specializations, we would have no primitive specializations. Which would be worse than the status quo.

这篇关于在 Java 8 中,是否有 ByteStream 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 20:24