• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

equals

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone explain this?

The Object class' equals() method just does an = = check, so if (ob1 = = ob2) is false, then ob1.equals(ob2) will always be false
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The == comparison operator tests values for equality. When applied to objects, that "value" is basically a reference (e.g., a memory address). Therefore, objA == objB if and only if they are, in fact, the same object (occupying the same space in memory).

The equals method is designed to be overridden to provide a more meaningful comparison of objects. For example, two separate instances of Car might be considered "equal" if they have specific variables in common (e.g., make, model, year, etc.). But in the simple case of Object, the equals method only checks whether the references point to the same object, just as the == operator does.
[ September 07, 2005: Message edited by: marc weber ]
 
Danger, 10,000 volts, very electic .... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic