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

  • SEARCH
  • Home
  • 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 6681043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:32:44+00:00 2026-05-26T04:32:44+00:00

The contract for equals(object) method specifies 4 properties to follow: Reflexive, Symmetric, Transitive and

  • 0

The contract for equals(object) method specifies 4 properties to follow: Reflexive, Symmetric, Transitive and Consistent. While I understand the danger of not following Reflexive, Symmetric and Consistent , and can definitely agree its good to follow transitive, I was wondering what harm it would bring if its violating the Transitive property?

Specifically, which of the Java library (or various third party libraries) need the dependency upon equals to be transitive to work correctly? In my understanding, the Collections framework will work if the other 3 properties are well implemented.

  • 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-05-26T04:32:44+00:00Added an answer on May 26, 2026 at 4:32 am

    Assume three objects a,b,c with

    a == a, b == b, c == c (reflexive)
    a == b, b == a
    b == c, c == b
    a != c, c != a
    

    (Pseudocode, x == y stands for x.equals(y)).

    Now, let’s add the objects to a set:

    Set s = new HashSet(); // Set implementation doesn't matter
    s.add(b); // s = [b]
    s.add(a); // s doesn't change, because a == b
    s.add(c); // s doesn't change, because c == b
    

    In contrast, if we were to add them in a different order:

    Set s = new HashSet();
    s.add(a); // s = [a]
    s.add(b); // s doesn't change, because b == a
    s.add(c); // s = [a,c], because c != a
    

    That is clearly counter-intuitive and doesn’t match the behavior one would expect of a set. For example, it would mean that the union of two sets (i.e. the state of s after s.addAll(someOtherSet)) could depend on the implementation (order of elements) of someOtherSet.

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

Sidebar

Related Questions

I've got multiple classes that, for certain reasons, do not follow the official Equals
The documentation for -hash says it must not change while a mutable object is
Is contract to interface as object is to class? What is the need to
When programming by contract a function or method first checks whether its preconditions are
I have a service contract that defines a method with a parameter of type
I have a domain object called User . Properties of user include ssoId, name,
If every object added to a java.util.HashSet implements Object.equals() and Object.hashCode() in a deterministic
I understand why providing same hashcode for two equal (through equals ) objects is
When overriding the equals() function of java.lang.Object, the javadocs suggest that, it is generally
I´ve often found an equals method in different places. What does it actually do?

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.