sealed interface I permits A, B, C, D, E, F, J {} final class A implements I {} final class B implements I {} final class C implements I {} final class D implements I {} final class E implements I {} final class F implements I {} final class J implements I {} record R(I i) {} class Main { static void testRecordExhaustive(R r){ switch (r) { case R(C i) -> {} case R(D d) -> {} case R(E e) -> {} case R(F f) -> {} } } static void testRecordNotExhaustive(R r){ switch (r) { case R(D d) -> {} case R(E e) -> {} case R(F f) -> {} } } static int testExhaustive1(I i) { return switch(i) { case C c -> 42; case D d -> 43; case E e -> 43; case F f -> 42; }; } static int testExhaustive2(I i) { return switch(i) { case C c -> 42; case D d -> 43; case E e -> 43; case F f -> 42; }; } static int testNotExhaustive1(I i) { return switch(i) { case D d -> 43; case E e -> 43; case F f -> 42; }; } static int testNotExhaustive2(I i) { return switch(i) { case C c -> 42; case E e -> 43; case F f -> 42; }; } static int testNotExhaustive3(I i) { return switch(i) { case C c -> 42; case D d -> 43; case F f -> 42; }; } static int testNotExhaustive4(I i) { return switch(i) { case C c -> 42; case D d -> 43; case E e -> 43; }; } class NestedGenerics { sealed interface JB { } record A(X x) implements JB { } record Wrap(A a) implements JB { static void main(JB jb) { switch (jb) { case A(var x) -> System.out.println(x); case Wrap(A(String s)) -> System.out.println(s); } } static void main2(JB jb) { switch (jb) { case A(var x) -> System.out.println(x); case Wrap(A(String s)) -> System.out.println(s); } } } } }