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}") } }

3/11/2018 2:08:01 PM

Greg Hurlock

1 Answer

New Answer


you can't put getter on parameters. just put get() function on the class itself