I want to create a class that can be used in SortedSet | SortedMap .
class MyClass implements Comparable<MyClass>{
Class instances must be sorted by their name. However, I do not want equally named instances to be considered equal.
So, the contents of the SortedSet will look like a, a, a, b, c .
(Normally, a SortedSet only allows a, b, c )
First of all: is it (philosophically) consistent?
If so, should I expect unpredictable behavior when I do not override equals(...) and hashCode() ?
Edit:
Sorry, my question seems inconsistent:
I want to put several "equal" values inside the set , which does not allow this by concept.
Therefore, please do not answer my question. Thanks to everyone who has already answered.
java collections
ivan_ivanovich_ivanoff
source share