I noticed that in Java 8 there are several versions of many types.
For example, the introduced class Optionalhas many varieties OptionalInt, OptionalLongetc.
Although it Optionalis of type Parameter ( Optional<T>), we still need some specific types for primitives, Why?
I cannot find the 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));
source
share