Java 27 and 26: runnable demos and captured output for every JEP, plus version lanes
Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B38FGKKam5SCGgwgduVAh3
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import java.util.List;
|
||||
import java.util.concurrent.StructuredTaskScope;
|
||||
import java.util.concurrent.StructuredTaskScope.Joiner;
|
||||
|
||||
/**
|
||||
* JDK 26 code for the structured concurrency preview. It compiles on 26 and fails on 27:
|
||||
* StructuredTaskScope gained a third type parameter (the exception join() throws), and
|
||||
* FailedException / TimeoutException no longer exist. Driven by scripts/broken-on-27.sh.
|
||||
*/
|
||||
public class StructuredScope26 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
try (StructuredTaskScope<String, List<String>> scope =
|
||||
StructuredTaskScope.open(Joiner.<String>allSuccessfulOrThrow())) {
|
||||
scope.fork(() -> "price=42");
|
||||
List<String> results = scope.join();
|
||||
System.out.println(results);
|
||||
} catch (StructuredTaskScope.FailedException e) {
|
||||
System.out.println("a subtask failed: " + e.getCause());
|
||||
} catch (StructuredTaskScope.TimeoutException e) {
|
||||
System.out.println("timed out");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user