0
Kotlin getters in constructor for inherit
I'm trying to understand how Kotlin constructors work. I want classes to inherit the legs and name fields below so I've put them in to the primary constructor. This works. I tried putting get in to the constructor also ... however this causes an exception. Where should the getter go if I want it to be inherited? open class Pet( var legs: Int, var name: String get() = field.toUpperCase() ){ fun SayName(){ println("My name is ${name}") } }
1 Antwort
0
you can't put getter on parameters. just put get() function on the class itself