Java Integer constant pool

Опубликовано: 31 Май 2026
на канале: Code Facts
230
11

Java caches Integer objects which have values in the interval [-128, 127]. This means that all Integer references with a value within that interval will point to the same object, hence the comparison is true for 127 and false for 128.

The `==` operator in Java compares references, not values. For comparing values, the `equals(Object o)` method inherited from Object is used. For example: `var1.equals(var2)`.