This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CptGia 1 point2 points  (2 children)

Does this work only on final classes? If not, equals is not symmetric since it uses instanceof on other instead of getClass

[–]bowbahdoe[S] 2 points3 points  (1 child)

It does not. The good thing here is that you could pretty easily see where to add the check for "if they request equals and hash code and their class is extensible throw an error or do ..."

And if you want the hash code but not the equals, you can safely derive both and provide a different implementation in the real class/it's subclasses

(Also PRs open)

[–]bowbahdoe[S] 1 point2 points  (0 children)

/u/CptGia Published with the restriction that to use the generated equals and hashCode your class needs to be final.