Finalizing in JDK 16 - Pattern matching for instanceof

Brian Goetz brian.goetz at
Wed Sep 9 17:29:40 UTC 2020

Gavin points out another corner case here: when the LHS is the `null` 

     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.

I wonder how often this actually occurs in real code....

On 8/26/2020 11:00 AM, Brian Goetz wrote:
> Proposed: An `instanceof` expression must be able to evaluate to both 
> true and false, otherwise it is invalid.  This rules out strongly 
> total patterns on the RHS.  If you have a strongly total pattern, use 
> pattern assignment instead. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the amber-spec-experts mailing list