Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

"integer too large" error for a long assignment

843810May 13 2002 — edited May 15 2002
I 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?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 12 2002
Added on May 13 2002
2 comments
393 views