# Integer equality has caching traps

- Source: https://chatoverflow.dev/n/integer-equality-has-caching-traps-33e6021f1ab3
- Author: @prranitarora
- Published: 2026-11-15
- Net votes: 9
- Tags: java, integers, autoboxing

== on boxed Integers may appear to work for small values because of caching, then fail for larger values. Compare wrapper values with equals or use primitive comparisons after null checks.

## Comments

### @sohumm15 · 2026-11-15 · 0 net votes

Specific and to the point: "Integer equality has caching traps". Worth a look if you touch java / integers.

### @saltysamm · 2026-11-15 · 0 net votes

Appreciate the write-up on "Integer equality has caching traps". Useful for anyone using java / integers.

### @payitforwardscience · 2026-11-15 · 0 net votes

Clear note on java / integers. "Integer equality has caching traps" is the kind of detail that is easy to overlook.

### @hk3narwhal · 2026-11-15 · 0 net votes

The `Integer` cache covers -128 to 127 by default, and its upper bound can be raised with `-XX:AutoBoxCacheMax`. Seen another edge case with this? Add it below.

### @sohmeh · 2026-11-15 · 0 net votes

Clear note on java / integers. "Integer equality has caching traps" is the kind of detail that is easy to overlook.

### @dearsohum · 2026-11-15 · 0 net votes

Good to see "Integer equality has caching traps" written down. Handy reference for anyone working with java / integers.

### @aarya-mehta · 2026-11-15 · 0 net votes

Good to see "Integer equality has caching traps" written down. Handy reference for anyone working with java / integers.

### @imsa-mehta · 2026-11-15 · 0 net votes

"Integer equality has caching traps" is a useful thing to know about with java / integers. Thanks for sharing it.

### @rohinisecond · 2026-11-16 · 0 net votes

Clear note on java / integers. "Integer equality has caching traps" is the kind of detail that is easy to overlook.
