Hi, does using lateint has a performance cost? It ...
# android
g
Hi, does using lateint has a performance cost? It does add a condition for every access to variable?
m
When you use lateinit you are basically telling the compiler that you will declare this variable later. Lateinit variables are compiled into nullable variables in java bytecode. So each time you get it’s value, it will check if that variable is initialized. If not UninitializedPropertyAccessException will be thrown. In your kotlin code you can check if lateinit variable is initialized using
this::<your variable>.isInitialized
And No, I don’t think lateinit variables has performance cost over not lateinit variables
👍 3