blob: 4153d5021a99ce52d33cd2915171bb0f85cfde81 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
public class RecordPatternsPreview1ExhaustivenessOK1 {
static Pair<A> p1 = new Pair<>(new A(), new B());
static Pair<I> p2 = new Pair<>(new C(), new D());
public static void main(String[] args) {
exhaustiveSwitch();
}
static void exhaustiveSwitch() {
switch (p2) {
case Pair<I>(I i, C c) -> System.out.println("x");
case Pair<I>(I i, D d) -> System.out.println("y");
}
switch (p2) {
case Pair<I>(C c, I i) -> System.out.println("a");
case Pair<I>(D d, C c) -> System.out.println("b");
case Pair<I>(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>(T x, T y) { }
|