Is `accountNumber` ```data class Account ( @ge...
# getting-started
d
Is
accountNumber
Copy code
data class Account (
    @get:JsonProperty("accountNumber")
    val accountNumber: kotlin.String? = null
)
considered to have a custom getter? Because that's what compiler complains about when I try to do this:
Copy code
val account: Account = TODO()
checkNotNull(account.accountNumber)
val number: String = account.accountNumber // error here
Why is it so?
r
works for me 🤔 , what error are you getting?
d
It is a bug, which was fixed by K2 compiler Works fine with 2.0.0
💡 1
👍 1
Actually there is still an issue with this code in case of incremental compilation, which is not fixed yet: KT-69075
d
Actually, my data class comes from an external module. Will smart casting ever be possible in such a situation?
d
Smartcasts on properties from other modules are prohibited by design: there is no guarantee that on runtime you won't receive a library of a different version, which, for example, added the custom getter
d
Ok, maybe a silly question: Why is
@get:JsonProperty("accountNumber")
considered a custom getter? It actually doesn't influence the field value in any way, does it?
d
For properties from other modules there is no difference if there are annotations on accessors or not. There shouldn't be smartcast even without an annotation