This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

equals( ) explanation ?  RSS feed

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What two statements are true about properly overridden hashCode() and equals()methods?


C. hashCode() can always return the same value, regardless of the object that invoked it.sure

E. equals() can be true even if it�s comparing different objects. why???what's the meaning of this???

thanks

[ October 15, 2006: Message edited by: saied ims ]

(removed shout in title)
[ October 15, 2006: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 2410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The definition of equals is up to the programmer. The only thing that you are required to do when you override the equals method is to return a boolean.
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The job of equals() is to compare two different objects meaningfully. This means you can have 2 separate references to 2 different objects and if the 2 objects are same according to the definition provided by the programmer, equals() will return true.

The default implementation of equals() in Object returns true only if you have references to the same object. You are expected to override it so that it returns true even if you have two different objects that are semantically equivalent.
[ October 15, 2006: Message edited by: Aniket Patil ]
 
saied ims
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks all
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!