I use a static use method that returns a completed future with an empty optional:
public class CompletableFutureUtils {
private static final CompletableFuture<Optional<?>> EMPTY_FUT = completedFuture(Optional.empty());
private static final Optional<?> EMPTY_OPT = Optional.empty();
@Nonnull
@SuppressWarnings("unchecked")
public static <T> CompletableFuture<Optional<T>> emptyOptionalCompletedFuture() {
return completedFuture((Optional<T>)EMPTY_OPT);
}
}
For efficiency, I want to return the same permanent instance of the completed CompletableFuture- EMPTY_FUT , but cannot pass it in CompletableFuture<Optional<T>>because of the unlimited template.
Of course, I want to call this completed future method for any type almost the same as Optional.empty () and CompletedFuture.completedFuture (U)
How to use a generic with an unlimited template for a specific type? Is it possible at all?
source
share