kotlin - 如何强制 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 中没有任何问题。
解决方案
添加注释@Nullable
@ProxyGen
@VertxGen
interface JobService {
@Fluent
fun getCertain(jobId: Int, handler: Handler<AsyncResult<@Nullable Job?>>): JobService
}
推荐阅读
- docker - Docker、主机操作系统重启和繁忙的端口
- javascript - 如何在滚动时显示和隐藏 div
- java - Java将跨度添加到图像背景颜色
- sql-server - T-SQL INSTEAD OF UPDATE 触发器:使用 INSERTED 表中的对应列更新所有列
- python - 为同一文件夹中的所有文件只定义一次python导入,这可能吗?
- mysql - 在mysql中选择最大值
- node.js - NodeJS中的非捕获分支重置正则表达式
- linq - 如何编写实体查询 linq?
- python - 根据字符串位置将 Pandas 系列分成多个 DataFrame 列
- centos7 - 使用 MPDF Centos 7