• Post Reply Bookmark Topic Watch Topic
  • New Topic

The road to equality  RSS feed

 
Winston Gutkowski
Bartender
Posts: 10574
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Original thread here: click.
- Stephan


Stephan van Hulst wrote:Can you give me an example where you would use super.equals()?

I almost always do, because I'm a "Child of Bloch", and I detest equals() methods that use getClass().

Indeed, I've even written a superclass that enforces it, which you can find described here if you're interested.

Winston
 
Stephan van Hulst
Saloon Keeper
Posts: 7932
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:It is required (or certainly advisable) if you use super.equals() because of the way Object.equals() is implemented.

Reading your article, I now understand what you mean here. I still disagree.



If this == obj, but we don't return prematurely, the method will still naturally return true. super.equals(this) will always return true (assuming the superclass is well-behaved). Then, if the Sub comparison is also well-behaved, the reflexivity property will hold for the entire method, regardless of the initial identity check. The check is just a performance boost.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!