JEP 453, fixing a wildcard in the code

Remi Forax forax at univ-mlv.fr
Wed Jun 7 07:46:00 UTC 2023


Hi all,
here is a minor fix to the code shown in JEP 453,
the type of "futures" uses a wildcard because the inference of scope::fork introduce it.

<T> List<Future<T>> executeAll(List<Callable<T>> tasks)
        throws InterruptedException {
    try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
    	  List<? extends Supplier<Future<T>>> futures = tasks.stream()
    	      .map(task -> asFuture(task))
     	      .map(scope::fork)
     	      .toList();
    	  scope.join();
    	  return futures.stream().map(Supplier::get).toList();
    }
}

I believe it's more readable to avoid inference and explicit set the type like this

      List<Supplier<Future<T>>> futures = tasks.stream()
          .map(task -> asFuture(task))
          .<Supplier<Future<T>>>map(scope::fork)
          .toList();
    
regards,
Rémi


More information about the loom-dev mailing list