• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

The road to equality

 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 14300
321
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic