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 1.1KB

1234567891011121314151617181920212223242526272829303132
  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. // TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed
  12. default -> System.out.println("z");
  13. }
  14. switch (p2) {
  15. case Pair<I>(C c, I i) -> System.out.println("a");
  16. case Pair<I>(D d, C c) -> System.out.println("b");
  17. case Pair<I>(D d1, D d2) -> System.out.println("c");
  18. // TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed
  19. default -> System.out.println("d");
  20. }
  21. }
  22. }
  23. class A { }
  24. class B extends A { }
  25. sealed interface I permits C, D { }
  26. final class C implements I { }
  27. final class D implements I { }
  28. record Pair<T>(T x, T y) { }