Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8640227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:13:42+00:00 2026-06-12T11:13:42+00:00

I was reading the paragraph quoted below from an article entitled- Java theory and

  • 0

I was reading the paragraph quoted below from an article entitled- Java theory and practice: Hashing it out – Defining hashCode() and equals() effectively and correctly

Defining equality
The Object class has two methods for making inferences about an object’s identity: equals() and hashCode(). In
general, if you override one of these methods, you must override both,
as there are important relationships between them that must be
maintained. In particular, if two objects are equal according to the
equals() method, they must have the same hashCode() value (although
the reverse is not generally true)
.[emphasis added by me]

My question relates to the latter bit of the paragraph “although the reverse is not generally true”. How is it possible for two different instances of a class to have the same hashCode but not be equal?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:13:43+00:00Added an answer on June 12, 2026 at 11:13 am

    In simple terms hashcode () is a function to generate hash by some formula, so there can be some collisions, two different values can turn out to have same hashcode.

    If I simply calculate the hashcode by taking mod by 6, then two different values might be having same hashcode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading Thinking in java , Generics. In one example(at paragraph The action
I am reading about clone from Effective Java It says that in clone the
so i was reading the intent-filters paragraph from the doc, but i can't really
I'm reading Effective Java Second Edition by Joshua Bloch and im confused by below
I was reading this article from this page , so let me present the
I'm reading this article and there is a paragraph: If you ever find yourself
I was (re)reading Joel's great article on Unicode and came across this paragraph, which
I was reading the Red Bean book and noticed this paragraph: Do not be
Reading the docs, I'd expect $(#wrap2).remove(.error) to remove all .error elements from #wrap2 .
Reading through this excellent article about safe construction techniques by Brain Goetz, I got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.