News for hackers. Stuff that matters.
Re:What's new in PHP 8? by croo on Monday August 17, 2020 @04:13AM (#24185110)
Reference comparison it is with a twist: the jvm caches the most common integers. You'll get the same object from -128 to +127 when implicitly assigning value. This is part of the spec, and can be set to a larger pool with -XX:AutoBoxCacheMax (but cannot be turned off).

If you explicitly ask for a new object (Long a = new Long(123l);) you will get a new object and the comparison will fail as expected.

The moral of the story is to always use .equals().

There are no comments on this comment yet.