Integer.valueOf caches -128..127, so == compares identical references inside that window and distinct ones outside it. Equality that passes every test with small fixtures fails the first time a real id arrives.
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-25