kotlinkotlin-reflect

Method reference to property setter


How could I get method reference to property setter without using kotlin-reflect?

Basically, if I'll write my code in java way it's super simple

fun setValue(i: Int) = Unit
val a: (Int) -> Unit = this::setValue

But for var value: Int I'm getting

var value = 1
val a: KMutableProperty0<Int> = this::value

Solution

  • Slightly shorter: just use this::value::set