首页 > 解决方案 > 如何强制 Vertx Rx CodeGen 生成 MayBe 作为返回类型

问题描述

我正在使用以下 Kotlin 代码生成代理(这也将生成 Rx 方法)

@ProxyGen
@VertxGen
interface JobService {
    @Fluent
    fun getCertain(jobId: Int, handler: Handler<AsyncResult<Job?>>): JobService
}

当我看到生成的 Rx 代码时,如下所示。

public Single<Job> rxGetCertain(int jobId) { 
   return new io.vertx.reactivex.core.impl.AsyncResultSingle<Job>(handler -> {
     getCertain(jobId, handler);
   });
}

问题:-

不幸的是,我无法在 Kotlin 中使用它,因为 kotlin 不允许非空字段使用空值,并且它会引发以下异常。

java.lang.IllegalArgumentException: Parameter specified as non-null is null

我如何强制 Vertx CodeGen 生成返回类型为 MayBe,以便我的代码在 kotlin 中没有任何问题。

标签: kotlinrx-java2vert.xrx-kotlincodegen

解决方案


添加注释@Nullable

@ProxyGen
@VertxGen
interface JobService {
    @Fluent
    fun getCertain(jobId: Int, handler: Handler<AsyncResult<@Nullable Job?>>): JobService
}

推荐阅读