Value equality (was: Value types questions and comments)
John Rose
john.r.rose at oracle.com
Tue May 17 05:06:08 UTC 2016
On May 16, 2016, at 8:29 PM, Kevin Bourrillion <kevinb at google.com> wrote:
>
> And by "deep equals" I mean equivalent behavior to
>
> https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#deepEquals-java.lang.Object:A-java.lang.Object:A- <https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#deepEquals-java.lang.Object:A-java.lang.Object:A->
>
> at least that is what AutoValue has been doing.
To the extent I understand this, it seems wrong: deepEquals treats arrays as if they are lists, which is an abstraction shift. Surely you aren't suggesting cracking a component reference in a subfield and treating its object as a List of its components, and so on recursively? Because that's what deepEquals does.
Or do you mean that, just as deepEquals avoids using op==(ref,ref) on array components, so "deep equals" should avoid using op==(ref,ref) on value components?
You can avoid op==(ref,ref) by replacing it by a call to ref.equals(ref), or you can avoid op==(ref,ref) by cracking the refs and recursing. That latter breaks an abstraction, so I think we agree it's bad, but *that* is a more "equivalent behavior" to Arrays.deepEquals.
— John
More information about the valhalla-spec-observers
mailing list