flâneur — a map of the web's best reading

Interviewer asked me why is 1 == 1 True but 1000 == 1000 False in Java? | by Harry | JavaGuides | Medium

medium.com · 199 words · saved by 1 readers

Guides on Java, Spring Boot, REST APIs, Full-Stack Web development, Microservices, Cloud, Databases, and tools with hands-on tutorials and best practices. Follow publication Top highlight Member-only story 3.1K 89 Listen Share I remember the first time I saw this in action. I had just wrapped my head around autoboxing in Java and thought, “Great, I can treat primitives and objects almost the same. Life is good.” And then, out of nowhere, my neat little test failed. My reaction? Pure rage. How the heck is 1 == 1 true but 1000 == 1000 false? Isn’t equality supposed to be straightforward? Spoiler: Java doesn’t care about your feelings. It cares about performance. Non members can read full article by clicking here! Let’s get one thing straight: == on objects doesn’t check value equality—it checks reference equality. The author made this story available to Medium members only. If you’re new to Medium, create a new account to read this story on us. 3.1K 3.1K 89 Guides on Java, Spring Boot, R

Explore this link on the map →

saved by