Lateinit modifier is not allowed on custom setter


#1

Can someone please explain, what is the reason for such lateinit behavior:

lateinit var bla: Any set(value) {}

Which results in compilation error: “Lateinit modifier is not allowed on properties with a custom getter or setter”


#2

This limitation is there to simplify the rules: lateinit properties are treated specially, and specifying a custom accessor makes their semantics less clear. But I agree that custom setter could be allowed. Feel free to file an issue in our YouTrack


#3

AFAIK custom setter is prohibited because lateinit properties expose their backing fields, unless they have a private setter.


#4

Good point. We could still have custom setters for private lateinit var’s though