A number like
4000000000000, which is too big to fit into a 32-bit signed
is interpreted as a literal of type
Large integer numbers have type long
Integer numbers without L or l suffix that are too large for an int are illegal
CorrectionHere is what's right.
In Java, large integral literals do not implicitly have type
To get a
long literal, one needs to add an
l as a suffix.
The following code would not compile:
long number = 12345678901234; // ERROR: integer number too large
The following code also would not compile:
long number = (long)12345678901234; // ERROR: integer number too large
The following tree shows the reason for this compiler error:
(long)12345678901234 is an expression consisting of a cast operator
and its operand, the number
However, as shown above, that operand is not a legal literal,
and thus the expression will not compile.
Java provides the suffix
l to allow expressing a long value as a literal:
long number = 12345678901234L; // OK: long literal
As the following tree shows, the literal
12345678901234L is an expression
long with value 12345678901234.