This Java snippet trips up even experienced developers 👇 Integer a = 127; Integer b = 127; Integer c = 128; Integer d = 128; System.out.println(a == b); System.out.println(c == d); One prints true. One prints false. At first glance, both comparisons look identical. Same type. Same assignment. Same operator. So what’s going on? If you know the reason, you’ve got a deeper grasp of how Java actually works under the hood. Drop your explanation below — no Googling 👇 #Java #Programming #SoftwareEngineering #DevCommunity #CodeChallenge
Good, nice explanation
Java caches Integer objects from -128 to 127. So a == b compares the same cached object → true. But 128 is outside the cache, so c and d are two different objects on the heap → false. Lesson: use .equals() for value comparison of objects; use == only when you intentionally want to compare references.