• 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

So,.. What does the == operator do, *exactly?

 
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good day comrade programmers.
As my expertise in the Java Programming Language advances, I'm studying and trying to understand new things(for me).

Let's talk about overriding the method hashCode()
I've overriden this method for a class I made, and made it return the int value of one of my instance variables.

Question: Does doing that mean that two objects of the class I made with the same value in the instance variable returned by method: hashCode() will be equal when I use the == operator?

Or will the == operator always use the bits contained in the reference variable even when hashCode() has been overriden?

PD. I suppose I could have just asked: Does overriding hashCode() affect how the == operator works?

Thank you very much in advance as always,
Your Friend,
Jose
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jose Campana:
I suppose I could have just asked: Does overriding hashCode() affect how the == operator works?


No it doesn't. == will always look at the exact object the reference point to, hashCode() has nothing to do with it.
 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdi, Rob.

Thank you. Your assistance is invaluable. It's so good to be able to receive help from someone who always responds confidently; makes it so much easier for me to digest a concept and move on to next one.

Have a Nice Day.

If someone has some further explanation, please let me know,
Best regards,
Jose
 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yes Mr.Augustine, it is there. thank you.
I'm glad you gave me that link, I need to do all the reading I can about the intricacies of Java.

Take care,
Jose
 
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

Originally posted by Jose Campana:
...I need to do all the reading I can about the intricacies of Java...


In that case, see JLS 15.21 Equality Operators and its subtopics.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jose,

I had a very long response typed.. but I noticed you asked for reading material - so I'll point you straight to the source:

http://developer.java.sun.com/developer/Books/effectivejava/Chapter3.pdf

Probably one of the best books on Java.. take a look at that.
 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

Adam, I'm overwhelmed by your response... and it's true, I need to do all the reading I can. Thanks for providing me the location of that online Book. I sure know it is the best book if you recommend it.

Once more, I gotta say this, you Guys rock! Java Ranch is the greatest online community of all time.

Thank you Mr. Adam.

See you next time.
Sincerely,
Jose
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic