Integer i and j built (using automatic boxing) from integer literals ranging from -128 to 127 and, therefore, they will be combined by the JVM, so they use the same object (see flyweight pattern ). Therefore, they are compared using object references.
For Double a and b on the other hand, such a union guarantee does not exist and, in your case, you have two different objects that did not compare the same.
Using == to compare objects, if you do not want to verify your identity, should be considered suspicious and should be avoided. The equals methods of both types are overridden to compare values ββin the box (as opposed to the identity of the object), so they return true in both cases (and should be used).
source share