• 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() method

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



please help me with three things.i got 1 and 3.so 1 and 3 verification needed.

1.If i only look at the relationship between equals and hashcode, then yes, it is valid.
2.If there is an option saying equals is invalid. .How do we say that this option is correct?(why i am asking means always this equlas() method is returning false for me)or for this problem,equals() method is valid.please clarify about this.
3.the hashcode() is propely implemented here.

Thanks in advance.
[ February 11, 2007: Message edited by: Shiva Mohan ]
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
equals method is not valid as it does not satisfy if a.equals(b) is true then b.equals(a) also be true.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Following is inValid logic that is why you are seeing equals returning false when both objects ontains "Shiva"

if(sValue.equals(b2)

Here it will always return false unless b2 is a String Object and contains the same value as sValue has.

if you modify it as
if(sValue.equals(b2.sValue)

equals implementation will be logically correct
 
reply
    Bookmark Topic Watch Topic
  • New Topic