public aspect RecordPatternsPreview1ExhaustivenessAspect { static Pair p2 = new Pair<>(new C(), new D()); public static void main(String[] args) { doSomething(p2); } public static void doSomething(Pair pair) { System.out.println(pair.toString().replaceAll("@[0-9a-f]+", "@000")); } before(Pair pair) : execution(* doSomething(Pair)) && args(pair) { switch (pair) { case Pair(I i, C c) -> System.out.println("x"); case Pair(I i, D d) -> System.out.println("y"); // TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 // has been fixed. But even with the default clause, it generates wrong byte code and throws runtime error: // NoSuchMethodError: 'I Pair.x()' default -> System.out.println("z"); } switch (pair) { 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"); // TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 // has been fixed. But even with the default clause, it generates wrong byte code and throws runtime error: // NoSuchMethodError: 'I Pair.x()' default -> System.out.println("d"); } } } sealed interface I permits C, D { } final class C implements I { } final class D implements I { } record Pair(T x, T y) { }