exhaustive switch statement and return

Jan Lahoda jan.lahoda at oracle.com
Fri Sep 30 12:20:35 UTC 2022


Thanks, I've filled:

https://bugs.openjdk.org/browse/JDK-8294670


Jan


On 30. 09. 22 13:59, Remi Forax wrote:
> Hi all,
> this code does not compile but i think it should.
>
> public class Example {
>    sealed interface Action {
>      record PrintAction() implements Action {}
>      record DeleteAction() implements Action {}
>    }
>
>
>    public int foo(Action action) {
>      switch (action) {
>        case Action.PrintAction printAction -> {
>          return 1;
>        }
>        case Action.DeleteAction deleteAction -> {
>          return 2;
>        }
>      }
>    }
> }
>
> regards,
> Rémi


More information about the amber-dev mailing list