Home United States USA — software A New Era for Determining Equivalence in Java?

A New Era for Determining Equivalence in Java?

259
0
SHARE

This article describes a recent proposal for improved Java equivalence with higher performant implementations of equals() and hashCode().
Let’s be friends:
Comment (0)
Join the DZone community and get the full member experience.
Liam Miller-Cushon has published a document simply called « Equivalence » in which he proposes « to create a library solution to help produce readable, correct, and performant implementations of equals() and hashCode(). » In this post, I summarize some reasons why I believe this proposal is worth reading for most Java developers, even if the proposal never gets implemented, and why the proposal’s implementation would benefit all Java developers if realized.
Miller-Cushon opens his proposal with a single-sentence paragraph: « Correctly implementing equals() and hashCode() requires too much ceremony. » The proposal points out that today’s powerful Java IDEs do a nice job of generating these methods, but that there is still code to be read and maintained. The proposal also mentions that « over time, these methods become a place for bugs to hide. » I have been on the wrong end more than once of particularly insidious bugs caused by an error in one of these methods and these can be tricky to detect.
All three editions of « Effective Java » provide a detailed explanation and examples for how to write effective implementations of these methods, but it’s still easy to get them wrong.

Continue reading...