Originally posted by adam lui:
i got further doubt on this issue.
Regarding Hashing, steps to retrieve(locate) an object are:
1.Find the right bucket (using hashCode() )
2. Search the bucket for the right element (using equals() )
ok, whats the effect using == instead on step 2?
i know this could be such a dumb question to many of java-ers here, but i reall y cant get through! pls help!
for Object type, equals() compares the values (333/343), not the types. the type must be the same to invoke the method. if the values aren't the same, it will return false, if the types aren't the same, it won't compile.
== when used to compare Object types compares the actual object references to see if they refer to the same Object.
Ovject ob1 = new Object();
Object ob2 = ob1;