Property reference from Java class

Consider a class/interface written in Java with a getter and corresponding setter.

public interface MyInterface {
    String getMyProperty();
    void setMyProperty(String s);
}

From Kotlin, the getter and setter are accessible via property notation. Also, we can obtain function references from both methods. But a property reference does not work.

fun f(my: MyInterface) {
    println(my.myProperty) // ok
    my.myProperty = "foo" // ok
    val getter = my::getMyProperty // ok
    val setter = my::setMyProperty // ok
    val prop = my::myProperty // does not work
}

Is there some reason to it or is it just not implemented. Is there another way to obtain a KMutableProperty from it? Note that in my use-case, the Java class comes from a library and is not modifyable. Also, there are many such cases and writing a wrapper for each of them is not feasible.

There is an issue for that: KT-8575: Support Java synthetic property references

1 Like