Depending on the configuration of your runtime, you may find the same behaviour with a larger range of Integer objects, including (Integer)1000. See the documentation for Integer#valueOf(int) and the Java® Language Specification (=JLS). Integer is not strictly a value class, but it has quite a lot in common with value classes. It is a bad idea to use the == operator on reference types anyway, and as the 3rd link tells you, == can give you misleading results on value classes' instances.
That JLS section wrote:. . . the rule disallows any assumptions about the identity of the boxed values on the programmer's part.
The only place where == might be permissible is in a cert exam. Otherwise it is poor coding.
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
Devious Experiments for a Truly Passive Greenhouse!