public class RecordPatternsPreview1ExhaustivenessOK1 { static Pair p1 = new Pair<>(new A(), new B()); static Pair p2 = new Pair<>(new C(), new D()); public static void main(String[] args) { exhaustiveSwitch(); } static void exhaustiveSwitch() { switch (p2) { case Pair(I i, C c) -> System.out.println("x"); case Pair(I i, D d) -> System.out.println("y"); } switch (p2) { case Pair(C c, I i) -> System.out.println("a"); case Pair(D d, C c) -> System.out.println("b"); case Pair(D d1, D d2) -> System.out.println("c"); } } } class A { } class B extends A { } sealed interface I permits C, D { } final class C implements I { } final class D implements I { } record Pair(T x, T y) { }