You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RecordPatternsPreview1ExhaustivenessOK1.java 771B

12345678910111213141516171819202122232425262728
  1. public class RecordPatternsPreview1ExhaustivenessOK1 {
  2. static Pair<A> p1 = new Pair<>(new A(), new B());
  3. static Pair<I> p2 = new Pair<>(new C(), new D());
  4. public static void main(String[] args) {
  5. exhaustiveSwitch();
  6. }
  7. static void exhaustiveSwitch() {
  8. switch (p2) {
  9. case Pair<I>(I i, C c) -> System.out.println("x");
  10. case Pair<I>(I i, D d) -> System.out.println("y");
  11. }
  12. switch (p2) {
  13. case Pair<I>(C c, I i) -> System.out.println("a");
  14. case Pair<I>(D d, C c) -> System.out.println("b");
  15. case Pair<I>(D d1, D d2) -> System.out.println("c");
  16. }
  17. }
  18. }
  19. class A { }
  20. class B extends A { }
  21. sealed interface I permits C, D { }
  22. final class C implements I { }
  23. final class D implements I { }
  24. record Pair<T>(T x, T y) { }