根据文档,executeBlocking
接口的Vertx
方法具有以下签名:
<T> void executeBlocking(Handler<Future<T>> blockingCodeHandler, boolean ordered, Handler<AsyncResult<T>> resultHandler)
问题是,为什么(从形式上看)以下原因使Java无法推断Future<T>
的通用类型(推断为Future<Object>
):
vertx.executeBlocking((deploymentFuture) -> {
this.deploy();
deploymentFuture.complete(new Boolean(true));
}, (asyncResult) -> {
start.complete();
});
即使deploymentFuture
被明确分配了Boolean
。只有此显式调用才给出Java Future<Boolean>
的概念:
vertx.<Boolean>executeBlocking((deploymentFuture) -> {
this.deploy();
deploymentFuture.complete(new Boolean(true));
}, (asyncResult) -> {
start.complete();
});
为什么在这种用例中推断类型这么麻烦?是因为类型不变(与ArrayList<Integer>
与ArrayList<Number>
相似)。
基本上没有明确的呼叫类型,我被扔掉了
No instances of type variable T exist so that Future<T> conforms to Future<Object>