• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Override Equals

 
Ranch Hand
Posts: 115
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


When we try to run this code, there is 2 compile time errors generate

TestOne.java:13: error: cannot find symbol
if((o instanceof TestOne ) && ( (TestOne)o.getTestValue() == thi
s.getTestValue() )){
^
symbol: method getTestValue()
location: variable o of type Object
TestOne.java:13: error: incomparable types: TestOne and int
if((o instanceof TestOne ) && ( (TestOne)o.getTestValue() == thi
s.getTestValue() )){
^
2 errors
 
Saloon Keeper
Posts: 12253
259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you're wondering why you're getting an error?

The dereference (dot) operator has higher precedence than the cast operator does. This means the compiler thinks you're trying to call getTestValue() before you're casting o to TestOne.

Aside from that, you shouldn't have statements of the form
Instead, do
Note your class does not conform to Object's contract. You're not overriding the hashCode() method in accordance with the equals() method.
 
Singh Harmeet
Ranch Hand
Posts: 115
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks mr. Stephan van Hulst , now my program is compiled successfully.......
 
To do a great right, do a little wrong - shakepeare. twisted little ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic