【发布时间】:2020-10-01 11:08:45
【问题描述】:
Android Kotlin,api.openOrder 返回类型为 BaseResponse<Profile>,
我想要的代码是,如果profile.value不为null,API返回BaseResponse<Profile>,否则,抛出异常:
suspend fun openOrder(qty: Int): BaseResponse<Profile> = withContext(IO) {
profile.value?.apply {
return@withContext api.openOrder(username, qty, createAuthCode(username))
} ?: throw Exception()
}
但是android studio提示这个有趣的返回类型是Any,如何解决?
排除if-else用法,因为profile.value有很多属性,而profile.value.username、profile.value.qty和很多profile.value.*不易阅读。
【问题讨论】: