Код: Выделить всё
import java.util.concurrent.CompletableFuture;
class Main {
public static class Promise extends CompletableFuture{}
public static void main(String[] args) {
System.out.println(System.getProperty("java.version"));
// This works:
CompletableFuture p1 = Promise.supplyAsync(()->{
return "foobar";
});
// This doesn't, but i need this:
Promise p2 = Promise.supplyAsync(()->{
return "foobar";
});
}
}
Ошибка:
Код: Выделить всё
ERROR!
/tmp/kpS1aJoUkj/Main.java:13: error: incompatible types: no instance(s) of type variable(s) U exist so that CompletableFuture conforms to Promise
Promise p2 = Promise.supplyAsync(()->{
^
where U is a type-variable:
U extends Object declared in method supplyAsync(Supplier)
1 error
Код: Выделить всё
ERROR!
Exception in thread "main" java.lang.ClassCastException: class java.util.concurrent.CompletableFuture cannot be cast to class Main$Promise (java.util.concurrent.CompletableFuture is in module java.base of loader 'bootstrap'; Main$Promise is in unnamed module of loader 'app')
at Main.main(Main.java:13)
Подробнее здесь: https://stackoverflow.com/questions/791 ... ablefuture
Мобильная версия