I need to compare hundreds of points to find path on 2D grid and I am really looking for performance.
I overridden equals()
in my Point
's class:
@Override
public boolean equals(Object o)
{
if (o instanceof Point)
{
Point that = (Point) o;
return that.i == this.i && that.j == this.j;
}
return false;
}
That's pretty good, because it's possible to compare my Point
to objects (which is used in ArrayList.contains()
), but I often need to compare Point
s among themselves.
So I overloaded equals()
:
public final boolean equals(Point other)
{
return (i == other.i) && (j == other.j);
}
The question is: is there any benefit from the second method? Is this faster to compare two Point
instances in cases when they are compared directly, and instanceof and cast are not required:
boolean result = onePoint.equals(otherPoint);
About platform: the code is compiled using android SDK(19) on android, and it is AOT-compiled using avian on iOS.
Thanks a lot.