我开始玩新的Java 21功能-pattern matching.
public class Main {
public static void main(String[] args) {
RecordB recordB = new RecordB(true);
switch(recordB) {
case RecordB b when b.bool() -> System.out.println("It's true");
case RecordB b when !b.bool() -> System.out.println("It's false");
}
}
record RecordB(boolean bool) { }
}
当编译上面的代码时,编译器生成信息the switch statement does not cover all possible input values
从我的Angular 来看,这不一定是真的.所以我的问题是:是否有任何保护模式总是使Switch表达式对于编译器来说不是穷举的,或者我在这里遗漏了什么?