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 · 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 You highlighted You're reading for free via Harry's Friend Link. Upgrade to access the best of Medium. Member-only story 2.7K 79 Listen Share More 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. In other words, a == b is asking, “Are these two variables pointing

Explore this link on the map →

saved by