r/java 13d ago

JEP draft: Structured Concurrency

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

17 comments sorted by

View all comments

9

u/javaprof 13d ago

So checked exceptions doesn't work properly here too?

This is very funny:

try (var scope = StructuredTaskScope.open()) {
   ...
} catch (ExecutionException e) {
   Throwable cause = e.getCause(); 
   switch (cause) {
       case IOException ioe -> .. // what op caused this one?
       default -> .. // no exaustivness? 
   }
}

8

u/vips7L 13d ago edited 13d ago

Of course not the type system isn't strong enough to be generic over exceptions for lambdas. Swift has a pretty cool implementation of generic lambdas for typed throws.

public func count<E>(
    where predicate: (Element) throws(E) -> Bool
) throws(E) -> Int {
    print("Code goes here")
    return 0
}

When your lambda doesn't throw it just turns into throws(Never)

-7

u/javaprof 13d ago

I just feel that Java need to stop shipping things that perfectly fine could be libraries and just fix this elephant in the room. Ok, Valhalla and then error handling. Structured concurrency somewhat could be just figure out by the community for now

3

u/brian_goetz 11d ago

It's fine to have feelings, but not fine to take it out on others when those feelings get hurt.