can i add custom getters to var/val in the main co...
# announcements
n
can i add custom getters to var/val in the main constructor of a data class ?
s
@Nikky This is the closest i could get. Pubic API has name backed by the private (hidden) member
Copy code
data class Person( private var privateName : String? ) {
    var name : String? = privateName
    get() {
        return field ?: "Unknown"
    }
}