Lateinit modifier is not allowed on custom setter

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”

3 Likes

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

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

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

2 Likes