[External] : Re: Remainder in pattern matching

Ali Ebrahimi ali.ebrahimi1781 at gmail.com
Thu Apr 21 06:25:09 UTC 2022


Hi Brian,
Please clear me for this case?

On Fri, Apr 1, 2022 at 6:26 PM Brian Goetz <brian.goetz at oracle.com> wrote:

>
>      Box<Box<String>> bbs = new Box(null);
>      switch (bbs) {
>          case Box(Box(String s)): ...
>          case null, Box b: ...
>      }
>
> has no remainder and will not throw.  Box(null) doesn't match the first
> pattern, because when we unroll to what amounts to
>
>      if (x instanceof Box alpha && alpha != null && alpha.value()
> instanceof Box beta && beta != null) {
>          s = beta.value(); ...
>      }
>      else if (x == null || x instanceof Box) { ... }
>
> What about this
     Box<Box<String>> bbs = new Box(new Box(null));
     switch (bbs) {
         case Box(Box(String s)): ...
         case null, Box b: ...
     }

Which case matches switch input?


-- 

Best Regards,
Ali Ebrahimi


More information about the amber-spec-observers mailing list