This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question regarding using equals()

 
kay lin
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:
For exam Objective 5.2
it says :
the compiler will not allow == if the classes are not in the same hierarchy..

now my question is what does it mean by "classes are not in the same hierarchy"...does it mean classes not in the package or something else??
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it's about inheritance. Parent class and subclass.


You can compare A and B, but you cannot compare String and Integer.
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:
No, it's about inheritance. Parent class and subclass.


You can compare A and B, but you cannot compare String and Integer.


One more thing, this will work...



EDIT: As per your subject line: question regarding using equals(). It looks like you are asking whether equals() will work or not when classes are not in the same hierarchy? Call to inherited equals() will work even if there is not inheritance relationship between the classes as discussed below.

e.g.,



Naseem
[ September 07, 2006: Message edited by: Naseem Khan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic