Object obj = new Point(1, 2);
if (obj instanceof Point(int x, var y)) { // record可嵌套
System.out.println(x+y);
}
switch模式匹配
switch (str) {
case null -> {} // 默认抛出NullPointerException
case "y", "Y" -> System.out.println("Yes");
case "n", "N" -> System.out.println("No");
case String s when s.equals("yes") -> System.out.println("Yes");
case String s when s.equals("no") -> System.out.println("No");
case String s -> System.out.println("Other");
}
switch (obj) {
case null -> System.out.println(); // 默认抛出NullPointerException
case String s when s.equals("one") -> System.out.println("one");
case String s -> System.out.println("many");
case Integer i -> System.out.println("int");
case Point(var x, int y) -> System.out.println(x+y);
default -> {}
}
有序集合
分代ZGC
Record模式
switch模式匹配
虚拟线程
对于CPU密集型任务,效果等同于
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())
注意:使用synchronized
或native
将使该虚拟线程独占一个平台线程从而导致阻塞,使用-Djdk.tracePinnedThreads=short
以跟踪该阻塞导出虚拟线程快照