Загрузка...

Java Interview Trick! 😵 | Java Puzzle Explained #shorts #javacoding #coding #codeprep #programming

Why does Integer a = 127; and b = 127; return true for a == b, but Integer c = 128; and d = 128; return false? 🤯

This Java behavior surprises many developers — but it’s actually due to Integer Caching! Java automatically caches Integer objects between "-128 to 127". So when you assign values in this range, Java reuses the same object. That’s why a == b returns true, they point to the same object. But 128 is outside the cache range, so c and d are created as different objects, and c == d returns false. This is a classic Java interview question — don’t get tricked!

👉 Follow CodeSnap for more mind-blowing Java tricks and coding facts!

Видео Java Interview Trick! 😵 | Java Puzzle Explained #shorts #javacoding #coding #codeprep #programming канала CodeSnap
Страницу в закладки Мои закладки
Все заметки Новая заметка Страницу в заметки