Equality

Doug Lea dl at cs.oswego.edu
Fri Dec 18 17:41:24 UTC 2015


On 12/18/2015 11:55 AM, Brian Goetz wrote:

> Here's the current thinking on the tools for equality:
>
>   - The bytecode set will provide sort of 'vcmpeq' instruction, whose behavior
> is a componentwise recursive comparison (int fields with icmp, value fields with
> vcmp, etc).
>   - The == operator in the language will correspond to vcmpeq
>   - The default (whether provided by javac or VM) implementation of equals(V)
> for value types will do an == comparison
>   - Users can override equals(V)
>
> The motivation for allowing overriding equals is the same as for objects.
> Obvious examples include Decimal(1.0) and Decimal(1.00), and
> Tuple[String,String] that both contain [ foo, bar ] but use different String
> instances to do so.
>
> On the signature of equality, equals() has potentially the same issue as
> contains(), where you might want to accept a broader set of comparands.  Still
> figuring out the options there.

Limiting value type V to only override equals(V x) seems to have
the same simplifying impact on Collection.contains and others. Yes?

-Doug




More information about the valhalla-spec-experts mailing list