Interface’s function clashes with Property’s getter

This feature seems not to be implemented in any way.

@AndreyBreslav’s comment on a similar question:

You can not override Java methods with Kotlin properties at the moment. It would be nice if we could support it, but we don’t know how to do it consistently for mixed hierarchies


This does not solve your problem but at least makes the code compile: you can change JVM name of the getter with the @JvmName annotation:

interface A {
    fun getFoo(): SomeType
}

class B: A {
    override fun getFoo() = foo

    val foo: SomeType = someValue()
        @JvmName("getFoo_") get() = field
}

Also, consider changing to a more idiomatic approach: define the val-property in your interface, so that you can override it in the implementations:

interface A {
    val foo: SomeType
}

class B : A {
    override val foo: SomeType = someValue()
}

class C : A {
    override val foo: SomeType
        get() = someCustomGetter()
} 

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)