文章目录
switch模式匹配
Switch模式匹配*(Pattern Matching for switch)*是java17的预览功能,知道java21才正式确定下来。简单说来,就是switch语法,可以代替instanceof了,这写起代码来方便了不少啊。用一个例子可以很好地试验这个特性:
public class SwitchTypeDemo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
Object x = JSON.