我有一些代码看起来像这样
fun onMessage(message: Message) {
message.property?.also {
repository.updateProperty(message.property)
}
}
Run Code Online (Sandbox Code Playgroud)
其中 的参数updateProperty()不可为空。编译器给出错误:
Smart cast to 'Property' is impossible, because 'Message' is a public API property declared in different module
解决这个问题的最佳解决方案是什么?
事实证明它就像使用it一样简单。
fun onMessage(message: Message) {
message.property?.also {
repository.updateProperty(it)
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2127 次 |
| 最近记录: |