All numbers in Java are supposed to be of int type. The following line is legal in Java>1.5
Short s = 1; // Will compile to Short s = Short.valueOf((short)1) - thus you can't exceed short max value i.e.
Short s = 4444; // is invalid for autoboxing
Same mechanics go for Integer
and Byte
instantiation. But Long works completely different. The following code gives compile time error
Long l = 10;
Long uses the same approach for autoboxing of long types, so
Long l = 10L; //is valid and is translated into Long.valueOf(10L)
I can't see why int cannot be assigned to a Long variable. Any thoughts on this matter?