I know that you can't use the delegated property syntax in Java, and won't get the convenience of "overriding" the set/get operators as in Kotlin, but I'd still like to use an existing property delegate in Java.
For instance, a simple delegate of an int:
class IntDelegate {
operator fun getValue(thisRef: Any?, property: KProperty<*>) = 0
}
In Kotlin of course we can use this like so:
val x by IntDelegate()
But how can we use IntDelegate
in some form in Java? This is the start, I believe:
final IntDelegate x = new IntDelegate();
And then using the functions directly. But how can I use the getValue
function? What do I pass for its parameters? How do I get a KProperty
for Java field?