"integer too large" error for a long assignment
843810May 13 2002 — edited May 15 2002I get a compiler error trying to directly assign the value 2 to the 32nd power (4294967296) to a long as shown in "CASE 1". Note that I can indirectly assign this value to a long as shown in "CASE 2" below.
CASE 1:
public class Test
{
public static void main (String[] args)
{
long testValue = 4294967296;
//long testValue = (Long.MAX_VALUE + 1) / (Integer.MAX_VALUE + 1);
System.out.println (testValue);
}
}
compiler result:
Test.java:5: integer number too large: 4294967296
long testValue = 4294967296;
^
1 error
print out when run:
none (doesn't compile)
CASE 2:
public class Test
{
public static void main (String[] args)
{
//long testValue = 4294967296;
long testValue = (Long.MAX_VALUE + 1) / (Integer.MAX_VALUE + 1);
System.out.println (testValue);
}
}
compiler result:
no errors
print out when run:
4294967296
I tried placing a 'L' after "4294967296" in "CASE 1:", but the compiler error remains. It pretty much doesn't seem to allow any value greater than Integer.MAX_VALUE to be directly assigned to a long. Compiler error? Anyone else seen this?