I noticed that, There are multiple versions of many Types in Java 8.
For example, The introduced Optional
class has many flavors of OptionalInt
, OptionalLong
etc..
Although the Optional
has a type Parameter (Optional<T>
), we still need some specific types for primitives, Why?
I cannot find a BIG difference between the following:
Optional<Integer> o = Arrays.asList(1, 3, 6, 5).stream().filter(i -> i % 2 == 0).findAny();
System.out.println(o.orElse(-1));
OptionalInt oi = Arrays.stream(new int[] { 1, 3, 6, 5 }).filter(i -> i % 2 == 0).findAny();
System.out.println(oi.orElse(-1));