• 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() and ==

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

For any two references, if == is true then equals() will always return true



Am I right? if not then Please correct

Thanks
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Based on the principle of reflexivity that imposes the equals(Object) contract which states that:

[...] x.equals(x) has to be true [...]

Your assertion is, logically, also true, as long as you are implying this with your question:

x == x is always true as long as x is not a float or double variable with a value of NaN.
[ May 26, 2006: Message edited by: Edwin Dalorzo ]
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


in your equals method. That's legal if foolish.

Or, also legal if foolish, you could just return a random number in a method called by equals and thus decide whether two instances are equal based on two random numbers.
[ May 27, 2006: Message edited by: Jeroen T Wenting ]
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



For any two references, if == is true then equals() will always return true



If u hav not overriden equals(Object) method in ur class from Object class, then equals(Object) method of object class will be called which actually rely on == operator.

So if references are true by == operator. Then inherited equals(Object) method will also return true.

regards

Naseem Khan
[ May 28, 2006: Message edited by: Naseem Khan ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic