I have a kotlin object defined as such:
data class UserUpdateRequest(val map: Map<String, Any?>) {
@get:Email
val email: String? by map
val firstName: String? by map
val lastName: String? by map
}
这很好,所以我遇到的问题是,属性是可以为空的,当我访问一个属性时,比如说,如果在映射中没有设置该属性,那么执行instance.email
就会抛出NoSuchElementException
.
Instead, it'd be more convenient if it returned null
, since it's optional/nullable. Is there any way to achieve this without writing my own delegate?