equals and hashCode

  • Thread starter Gregory A. Swarthout
  • Start date
G

Gregory A. Swarthout

From Object's JavDoc:
If two objects are equal according to the equals(Object)
method, then calling the hashCode method on each of
the two objects must produce the same integer result.

It doesn't say why this must be. Does anyone know?
 
S

Silvio Bierman

Gregory A. Swarthout said:
From Object's JavDoc:


It doesn't say why this must be. Does anyone know?

Look at what Wendy wrote. Without this requirement using hashing in general
container classes (HashMap, HashSet) would not be feasible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,191
Latest member
BuyKetoBeez

Latest Threads

Top