tags:

views:

450

answers:

4
    assertEquals( new Long(42681241600) , new Long(42681241600) );

I am try to check two long numbers but when i try to compile this i get

    integer number too large: 42681241600

error. Documentation shows there is a Long,Long assertEquals method but it is not called.

+9  A: 

You want:

assertEquals(42681241600L, 42681241600L);

Your code was calling assertEquals(Object, Object). You also needed to append the 'L' character at the end of your numbers, to tell the Java compiler that the number should be compiled as a long instead of an int.

AgileJon
+6  A: 

42681241600 is interpreted as an int literal, which it is too large to be. Append an 'L' to make it a long literal.

If you want to get all technical, you can look up §3.10.1 of the JLS:

An integer literal is of type long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int (§4.2.1). The suffix L is preferred, because the letter l (ell) is often hard to distinguish from the digit 1 (one).

Michael Myers
+2  A: 

append an "L" at the end of your number, like:

new Long(42681241600L)

in Java, every literal number is treated as an integer.

cd1
A: 

You should also generally consider using Long.valueOf since this may allow some optimisation:

Long val = Long.valueOf(1234L);

From the J2SDK:

public static Long valueOf(long l)

Returns a Long instance representing the specified long value. If a new Long instance is not required, this method should generally be used in preference to the constructor Long(long), as this method is likely to yield significantly better space and time performance by caching frequently requested values.

paulcm