record Top(Child c1, Child c2) {} record Child(I x, I y){} record Wrong(int x) {} record TypedRecord(T t) {} sealed interface I permits A, B {} final class A implements I {} final class B implements I {} public class Test { void test(Object o, Integer i){ switch (o){ if (o instanceof Child(A a)){ } if (o instanceof Child(A a1, A a2, A a3)) { } if (o instanceof Child(A a, B b)){ } if (o instanceof Top(Child a, Child(int x, I y))){ } if (o instanceof Top(Child a, Child(A a, I y))){ } if (o instanceof Top(Child a, Wrong(int x))){ } if (i instanceof Wrong(int x)) { } } } void testRawDeconstruction(TypedRecord r) { if (r instanceof TypedRecord(I t)){ } if (r instanceof TypedRecord(T t)){ } if (r instanceof TypedRecord(I t)){ } if (r instanceof TypedRecord(T t)){ } } void resolveHighlighting1(Object o){ if (o instanceof Child(A a, B b)){ System.out.println(a); } else { System.out.println(a); System.out.println(c); } } void resolveHighlighting2(Object o){ if (!(o instanceof Child(A a, B b))){ System.out.println(a); System.out.println(c); } else { System.out.println(a); } } void resolveHighlighting3(Object o){ if (!(o instanceof Child(A a, B b))) return; System.out.println(a); } void resolveHighlighting4(Object o){ if (o instanceof Child(A a, B b)) return; System.out.println(a); } }