JEP 430: String Templates(Preview) • JEP 440: Record Patterns • JEP 441: Pattern Matching for switch • JEP 443: Unnamed Pattens and Variables(Preview) • JEP 445: Unnamed Classes and Instance Main Methods(Preview) • JVM • JEP 439: Generational ZGC • JEP 451: Prepare to Disallow the Dynamic Loading of Agents
431: Sequenced Collections • JEP 442: Foreign Function & Memory API(Third Preview) • JEP 444: Virtual Threads • JEP 446: Scoped Values(Preview) • JEP 448: Vector API(Sixth Incubator) • JEP 452: Key Encapsulation Mechanism API • JEP 453: Structured Concurrency(Preview) • JDK • JEP 449: Deprecate the Windows 32-bit x86 Port for Removal
java.util.ArrayList; public class Test{ } >javac Test.java Test.java:1: error: extraneous semicolon import java.util.List;; ^ 1 error import java.util.List;; public class Test{ } OK, because semi-colons after import block are allowed
are too heavy to reuse thread during waiting network IntStream.range(0, 100_000) .forEach(_ -> Thread.ofVirtual() .start(() -> sleep(ofSeconds(3)))) IntStream.range(0, 100_000) .forEach(_ -> Thread.ofPlatform() .start(() -> sleep(ofSeconds(3))))
different thread, synchronizing the subtask is required. But using `wait` and `join` will make “go-to hell” like complexity. • Structured concurrency preserves the natural relationship between tasks and subtasks. try (var scope = new StructuredTaskScope.ShutdownOnFailure()) { Future<String> user = scope.fork(() -> findUser()); Future<Integer> order = scope.fork(() -> fetchOrder()); scope.join(); // Join both forks scope.throwIfFailed(); // ... and propagate errors // Here, both forks have succeeded, so compose their results return new Response(user.resultNow(), order.resultNow()); }
可能な型を限定できない • sealed型で限定 sealed interface Type { record Bulk(int price, int unit) implements Type {} record Packed(int price) implements Type {} } sealed interface Type permits Bulk, Packed {} record Bulk(int price, int unit) implements Type {} record Packed(int price) implements Type {}
Item(Product product, int amount) {} var cart = List.of( new Item(new Product("餃子", new Packed(300)), 3), new Item(new Product("牛肉", new Bulk(250, 100)), 230));
switch(item) { case Item(Product(var n, Packed(int price)), int amount) -> price * amount; case Item(Product(var n, Bulk(int price, int unit)), int amount) -> price * amount / unit; }).sum();