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.3KB

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