You need to know the difference between Long and Long - Long is a primitive type, Long is a shell type. (A bit like a box value in C #, but strictly typed.) What type of getId() return?
Just:
assertEqual(id1, id2);
It should be good if you do this in a test. Otherwise, you can use:
if (id1.equals(ids2))
if they are definitely not null, or use Guava :
if (Objects.equal(id1, id2))
to handle invalidation. (You can write Objects.equal yourself, of course, but you definitely need to get hold of Guava, so you could also use this ..)
It is worth noting that some wrapper objects are reused - for example, for example:
y = 10000L; assertTrue (x == y); // Compare links
Jon skeet
source share