In the example below, the first line of foo creates a clean inlined getter from a property reference Object::x.
How can I achieve the same for a setter in a concise way? Neither Object::x nor Object::x.setter work.
class Object {
var x: Int = 0
inline fun <T> inlineGetter(getter: (Object) -> T): T {
return getter(this)
}
inline fun <T> inlineSetter(setter: (Object, T) -> Void, value: T): T {
setter(this, value)
return value
}
fun foo() {
val a = inlineGetter(Object::x)
val b = inlineSetter(Object::x, 1) // does not work!
}
}
What I want is a replacement for val b = inlineSetter({ o: Object, i: Int -> o.x = i}, 1), which is clearly too much boilerplate but compiles to the expected PUTFIELD: