java - Does it make sense for equals and compareTo to be inconsistent? -
I want to make a code usable in SortedSet . Sorted Map .
class MyClass implies Comparable & lt; MyClass & gt; {// Simply relevant thing for comparison: the name of the private last string; // ...} Class examples should be resolved by the property of their name.
However, I do not want to equate equally named examples as equal.
Then a sorted set content looks like a, a, a, b, c
(Generally, sorted sets a, b, c )
First: Is it (philosophical) analogous?
If so, when I have equals (...) and hashode () ?
Do not override, so do I expect unexpected behavior, edit:
I'm sorry, my question is incompatible:
I have to do Multiple "identical" values are to be placed within set , which is not allowed by this concept.
Now, please do not answer my question. Thanks for all those who have already responded.
Let me ask you a question: is this a.compareTo (b) Returns 0a Nd a.equals (b) returns false ?
I will use one instead. This is the reason for implementing all the sorted map / sortedset I know that you have permission to create a Comparator .
Comments
Post a Comment