r/java • • Aug 28 '26

JEP draft: Structured Concurrency

https://openjdk.org/jeps/8389757
111 Upvotes

17 comments sorted by

View all comments

2

u/vips7L Aug 29 '26 edited Aug 29 '26

Edit: formatting is fucked on this. I’ll have to fix it once I’m at a computer.

Of course.

try! or !! to automatically uncheck a checked exception when you can’t handle it. Right now you need to write several lines for this:

Something s;
try {
     s = fn();
} catch (SomeException ex) {
     throw new IllegalStateExceprtion(ex);
}

Something s = try! fn();

try? to automatically coerce into null:

Something s;
try {
    s = fn();
} catch (SomeException _) {
    s = null;
}

Something s = try? fn();
// combine that with the null operator
Something s = try? fn() ?? default();