Probably asked several times here already, searching didn’t return a direct answer, so please forgive me asking.
While writing a blog post about delegation in Kotlin [1] I tried to create an interface with a getter.
interface HasName {
fun getName():String
}class Person(val name:String)
This does not work. I wanted to confirm that this is not possible, or where I’m doing something wrong. How would I implement this?
class Person(val n:String) {
fun getName():String = n
}
or
class Person(n:String) {
val name = n
}
[1] http://codemonkeyism.com/exploring-delegation-in-kotlin/