简体   繁体   English

Vert.x 如何在 lambda function 中向 promise 添加类型参数

[英]Vert.x how to add type parameter to promise in lambda function

I am recently using vert.x framework in java and I am still new to vert.x.我最近在 java 中使用 vert.x 框架,但我还是 vert.x 的新手。

Normally when we initiate future as the following way the SMObj automatically assigned to promise1 promise.通常当我们按照以下方式启动future时, SMObj自动分配给promise1 promise。

Future<SMObj> future = Future.future(promise1 -> {
      ----
});

What I want to know is, When I use vertx.executeBlocking as following code segment, is there a possible way to set type parameter as SMObj to promise2 (eg: promise2 should be like Promise<SMObj> )我想知道的是,当我使用vertx.executeBlocking作为以下代码段时,是否有可能将类型参数设置为SMObjpromise2 (例如:promise2 应该类似于Promise<SMObj>

vertx.executeBlocking(promise2->{
          ----code-----
          promise2.complete(SMObj);
      }, blockRes->{ 
          ----code-----
      }
);

Sure you just have to use the diamond operator:当然,您只需要使用菱形运算符:

vertx.<SMObj>executeBlocking(promise2 -> {
   promise2.complete(SMObjInstance);
}, blockRes -> {
   ---- code ---
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM