Why can't the Java compiler directly cast an int
to a Long
?
long test = 1; // ok
Long test2 = 2; // does not compile!
Long test3 = 3L; // ok
It's especially frustrating since (of course) one can do
long test = 1;
Long test2 = test;
Is it a deliberate design choice? What could go wrong if this was allowed?