I am wondering why casting a primitive data type (int
for instance) to a reference type (Long
for instance) does not compile?
BinaryOperator<Long> add = (x, y) -> x + y;
System.out.println(add.apply((Long)8, (Long)5)); //this line does not compile
System.out.println(add.apply((long)8, (long)5)); // this line does compile
I will be happy to have some detailed answer. Thank you.