Originally posted by Jeroen Wenting:
I think the idea that autoboxing should cause == to work on object content for wrapper classes rather than on the object references (as you seem to imply) is a bad one.
Are you saying that:
To me, the latter is more in line with the stated purpose of autoboxing/unboxing which is to eliminate the drudgery of manually converting from primitive to wrapper and vice versa. I would think that if you wanted the former and still have autoboxing, you'd have to write
instead. If (a == b) were equivalent to (a.equals(new Integer(b)), not only are you automatically converting the type of the variable b, you're also changing the == operator to behave like a call to the equals() method of the Wrapper class. That would be even more confusing because it's doing two things rather than just the one thing of unboxing the int value from a and then performing the == operation as normal.