Consider this: Interface with a property. Class im...
# getting-started
e
Consider this: Interface with a property. Class implements the interface using primary constructor with a parameter that overrides the property. Nice and easy. Now: How can I transform the argument value before that? There sure must be a better way than this:
Copy code
interface Foo { val text: String }

class Bar (private var text2: String) : Foo {
    init {
        text2 = text2.replace('a', 'z')
    }
    override val text: String
        get() = text2
}
k
Use a constructor parameter instead of an immediate property declaration:
Copy code
class Bar(text: String): Foo {
    override val text = text.replace('a', 'z')
}
e
Doh. I was sure that there’s a simple solution. embarrased Thanks!