Problem Statement
How do extension properties work in Kotlin and what are their limitations compared to regular properties?
Explanation
Extension properties add properties to existing types without modifying them, declared like extension functions with the type before the property name like val String dot lastChar colon Char get open paren close paren equals get open paren length minus 1 close paren. They must have custom getters since they cannot have backing fields.
Extension properties cannot store state because they don't have backing fields, so they must compute values from the receiver object's existing state or be constant. Var extension properties require both getter and setter, and the setter receives the new value to validate or transform before applying to receiver properties.
Use extension properties for computed values derived from existing properties like collection dot isEmpty as extension of List, or for providing convenient property syntax for methods. They make code more readable by allowing property syntax instead of method calls for side-effect-free computed values.
Limitations include no backing fields, no initialization, cannot override in subclasses since resolved statically, and cannot access private members. Despite limitations, extension properties improve API expressiveness for calculated values that conceptually feel like properties.
