在Java 8中,我发现这有点奇怪。我似乎无法从byte[]
数组中创建字节流。 Array.stream
课程似乎仅适用于int[]
,long[]
,double[]
或T[]
。
public long update(final byte[] buffer) {
crc = 0L;
Arrays.stream(buffer).forEach(this::update); // expecting to go into a function update(byte b)
return crc;
}
当我尝试Stream.of(buffer)
或Arrays.asList(buffer).stream().forEach(this::update);
之类的替代方案时,流只是反映了自己,我得到了byte[]
。
我在这里的实现中遗漏了什么?