Providing an alternative to equals()?
<p>Let's say I have a class called <code>Number</code>, and I intend to do a lot of equality comparisons of <code>Number</code> objects. I am concerned about the "overhead" (class comparison, etc...) of the generic <code>Number::equals(Object o)</code> method. In this case, is it useful to provide a method such as <code>Number::isEqualTo(Number other)</code> as an alternative to <code>Number::equals(Object o)</code>? Is this a common pattern? Or do JVMs currently optimize well enough that there is no advantage to doing this?</p>

<p>Here's a code example:</p>

<pre><code>public class Number {
    int _value;

    Number(int value) {
        _value = value;
    }

    @Override
    public boolean equals(final Object o) {
        if (o == this) return true;
        if (o == null) return false;
        if (o.getClass() != getClass()) return false;
        return isEqualTo((Number)o);
    }

    public boolean isEqualTo(final Number other) {
        return _value == other._value;
    }

    public static void main(String[] args) {
        Number one = new Number(1);
        Number two = new Number(2);
        if (!one.isEqualTo(two)) {
            System.out.println("fast comparison?");
        }
        if (!one.equals(two)) {
            System.out.println("slow comparison?");
        }
    }
}
</code></pre>
