【发布时间】:2017-05-29 07:28:30
【问题描述】:
我正在尝试找出如何在kotlin中实现“if let + cast”的组合:
迅速:
if let user = getUser() as? User {
// user is not nil and is an instance of User
}
我看到了一些文档,但他们对这种组合只字未提
https://medium.com/@adinugroho/unwrapping-sort-of-optional-variable-in-kotlin-9bfb640dc709 https://kotlinlang.org/docs/reference/null-safety.html
【问题讨论】: