Finalizing in JDK 16 - Pattern matching for instanceof
Dan Smith
daniel.smith at oracle.com
Thu Sep 10 20:03:31 UTC 2020
> On Sep 9, 2020, at 11:29 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
>
> Gavin points out another corner case here: when the LHS is the `null` literal:
>
> if (null instanceof String s) { ... }
>
> Since this is also in the "stupid question" category, it is reasonable to outlaw it, at least when there's a pattern on the RHS.
One thing to be careful of with "stupid question" errors is that sometimes stupid questions can be useful for experimentation. For example, it's nice that I can go to jshell and see what 'null instance String' does without getting my hand slapped.
(I don't think there's a bright line between stupid questions that should be disallowed and those that should are useful. It's a judgement call.)
More information about the amber-spec-experts
mailing list