Why is it not possible to use lateinit
with Boolean
in Kotlin? I tried it with the other primitive data types and it works fine!
Here is the code that I want to use:
object BankAccount {
lateinit var accountName: String
lateinit var accountNumber: String
lateinit var accountStatus : Boolean
}
This is what the error says:
'lateinit' modifier is not allowed on properties of primitive types
lateinit
doesn't work with primitive or nullable types, because internally it usesnull
as "uninitialized" value. Since fields of primitive types can't benull
, the internallateinit
mechanism can't work.You probably misread something.
lateinit
doesn't work with any primitive types.