Some objects are more equal than others - a look at the many meanings of equality, value and identity

By Roger Orr & Steve Love

Equality is a fundamental concept in programming but is surprisingly hard to get right. Its importance is shown by the way that in most languages it is a symbol (not even a keyword) - although the variation between "=" and "==" continues to catch people out!

In languages that allow you to define your own types it is important to get equality right -- but what does "right" mean in practice?

We will look at the slippery concepts of equality, value and identity and discuss what pitfalls there are in using them. This is important in places as varied as database persistence and reliable unit tests - and also becomes a 'key' issue when you are working with associative collections.

Equality can be hard enough to get right for a single class; but additional issues arise with hash codes for objects and when you start using class hierarchies. We will work through an example of trying to get this right based on experience with real-world problems.





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.