[patterns] Nullability in patterns, and pattern-aware constructs (again)

John Rose john.r.rose at oracle.com
Fri Jan 10 21:55:13 UTC 2020

On Jan 10, 2020, at 1:18 PM, Guy Steele <guy.steele at oracle.com> wrote:
> Well, if the _only_reason to allow instanceof with a constant is floats and doubles (comparing to NaN is the one thing that == or .equals might not handle properly), then it’s not a very good reason; I dare say Float.isNan(x) is the first thing that would jump to mind, and it would be a whole lot more readable as well.

The refactoring story is another reason: Allowing instanceof
simplifies refactoring, and also any spec that appeals to desugaring.

A complicated pattern might contain a constant K somewhere.
It’s surely better to desugar uniformly to instanceof applications,
and *then* note that in some cases  x instanceof K can be further
desugared to (Float.isNan(K) ? Float.isNan(x) : x == K), when x is
a float.

More information about the amber-spec-experts mailing list