Getters vs. public final fields in records

Andrew Cave ajcave at google.com
Sat Aug 13 18:20:34 UTC 2022


>
>
> Except you've got your mappings the wrong way around.
>

Ok, let’s go with that:

(new R(a)).p() <= a

It’s difficult to be precise, because you haven’t spelled out the entire
semantics (and I’m pretty sure it doesn’t exist), but, if we are able to do
some kind of “normalization”, we are presumably able to do the simplest
imaginable kind:

record R(Boolean b) {
  Boolean b() { return true; }
  bool equals(Object o) { return true; }
}

And also:

record S(Boolean b) {
  Boolean b() { return false; }
  book equals(Object o) { return true; }
}

from which we can deduce:

false = S(true).b() <= true

And

true = R(false).b() <= false

So true <= false and false <= true, hence true = false, and since you
interpret “=“ as .equals, we are forced to make .equals() on Boolean say
that true is equal to false.

The key here is that <= in “R(a).p() <= a” is the one defined on the domain
(type) of *a* and you don’t get to choose what it is as part of the
definition of your record; it’s already chosen for you!

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20220813/3f386ad4/attachment.htm>


More information about the amber-dev mailing list