If I have
Float f1 = 5.25f;
Float f2 = 5.25f;
Then
f1 == f2
is false. Though
f1.equals(f2);
is true. Why is it so, I thought that if the unboxing is executed, then f1 == f2 should compare
f1.floatValue() == f2.floatValue();
the same as
f1.equals(f2);
should do. What is wrong?
UPDATE: No I see the answer, because Java compares references for Float objects too. I asked the question because I had
Long l = 15l;
Long l2 = 15l;
But the
System.out.println(l == l2);
output was
true
So I was misleaded, and thought that numeric type objects are compared by value when using ==. But I found, that comparison of small long values will return true, because small long values are cached!