exhaustive switch statement and return

Remi Forax forax at univ-mlv.fr
Fri Sep 30 11:59:04 UTC 2022


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