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 3842774
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:50:31+00:00 2026-05-19T15:50:31+00:00

More specifically I want an interface to compare objects which can be only compared

  • 0

More specifically I want an interface to compare objects which can be only compared for equality [e.g. complex numbers] but don’t have total order on them.
It should have [Note that it only returns a boolean yes/no]

boolean Equals(T object1, T object2);

and a hashcode function. So that when I distribute them into buckets using objects say to collect “equal” objects, 2 “equal” objects don’t end up in two different buckets.

int getHashCode(T object);

Does Java have one? I searched and couldn’t find it.

I am trying to use this in Hadoop Map Reduce to distribute “equal” objects to same reduce job so that I can operate on all “equal” objects. I only care about whether objects are equal or not and don’t need total order. But if two objects are equal they should have same hash code. Otherwise they will end up in two different reduce jobs.

Please note that I know about equals and hashcode of object. But I want an external comparator which say depends on only part of an object. So object’s notion of equality differs from mine.

  • 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-19T15:50:32+00:00Added an answer on May 19, 2026 at 3:50 pm

    There’s no built-in type that is used for this in Java. It’s a “hole” in the collections design, IMO. There’s the string-specific Collator class which is about as close as it gets, I’m afraid.

    There’s no way of customizing the built-in maps to use a specific kind of equality comparison, worse luck. It’s entirely reasonable to want this functionality, and a real pain that it’s not already present.

    You could create your own such interface of course, and write your own map variants which use it… but having to do so sucks 🙁

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

Sidebar

Related Questions

I want to learn APL (more specifically Dyalog APL), but I can't seem to
http://developer.yahoo.com/yui/button More specifically, I want radio buttons. that can be checked/unchecked.
More specifically I want to test whether Oracle ODP.Net is installed on a machine.
I want to add a context menu to the tableview, more specifically I want
...or more specifically, how are they able to create animations via javascript, which is
I want to look more into the workings of Android. More specifically I want
I have a Java Application and want to interface Ogre inside it. Specifically Ogre
I want to do something like this in C# (more specifically, WPF): Thread.Invoke(MyCallback, 1000);
More specifically: I want to find this information from inside the program, preferably just
I'm using the CollectionResolver (more specifically the ListResolver) to support scenarios where we want

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.