I have a simple Stream
that is meant to work on Bytes:
List<Byte> byteList = Arrays.stream(new Byte[]{0x1, 0x2, 0x3, 0x4})
.map(b -> b >> 1)
.collect(Collectors.toList());
The compiler gives:
Error: incompatible types: inference variable
T
has incompatible boundsequality constraints:
java.lang.Byte
lower bounds:
java.lang.Integer
And this also does not work:
Optional<Byte> aByte = Arrays.stream(new Byte[]{0x1, 0x2, 0x3, 0x4})
.map(b -> b >> 1)
.findFirst();
Error: incompatible types:
java.util.Optional<java.lang.Integer>
cannot be converted tojava.util.Optional<java.lang.Byte>
I did not find any documentation stating that streams do not support Byte
. Any pointers?
b >> 1
returns an int which can't be automatically cast to byte. You can just add a cast: