Answer the question
In order to leave comments, you need to log in
How to correctly implement Comparable in this case?
I have a Vector3 structure that has three coordinates on each of their axes. For the algorithm, I need to check if an element is contained in a set.
How can I make the set check the elements according to my rule, and not according to its own?
I tried to implement Comparable, but did not get the desired result:
@Override
public int compareTo(Object o)
{
Vector3 vector3 = (Vector3) o;
if (x == vector3.getX() && y == vector3.getY() && z == vector3.getZ())
return 0;
else return -1;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question