我正在尝试实现Spring Async,但在尝试将类引用传递给CompletableFuture时遇到问题。
public final class Test<T> {
final String id;
final Class<T> type;
public static <T> Test<T> key(String id, Class<T> type) {
return new Test<>(id, type);
}
}
现在,我想创建一个常量,并通过类型擦除将类引用传递给
。public static final Test<CompletableFuture<Student>> variable = Test.key("variable", CompletableFuture.class); //compilation error
public static final Test<CompletableFuture> variable = Test.key("variable", CompletableFuture.class); //works but complaints about raw type
请提出建议,如何在确保类型安全的同时传递类引用。