In the first case, you compare a Long
reference with the long
primitive type, in which case the Long
reference undergo automatic unboxing conversion, and the comparison is done between two primitive longs, and hence they are equal. This is in accordance with JLS §5.6.2 - Binary Numeric Promotion.
While in second case, you are comparing two different references, both pointing to two different objects, and hence they have different value, and return false
.