Joshua Hansen
10/22/2025, 6:32 PMclass Foo {
var number: Int = 0
}
Is it possible to pass a reference to the number property to another class so that the other class can reassign it?Michael Krussel
10/22/2025, 6:49 PMKMutableProperty1 to a function and get an instance of from ::number.
You can also access the setter from it pass it somewhere as a Function.Stephan Schröder
10/22/2025, 7:21 PMval foo = Foo()
val setter: (Int)->Unit = { newValue -> foo.number = newValue }
class Bar( val setNumber: (Int)->Unit )
val bar = Bar(setter)Ruckus
10/22/2025, 7:22 PM::number::set to get a `(Int) -> Unit`:
fun main() {
val foo = Foo()
val bar = Bar()
bar.run(foo::number::set)
println(foo.number)
}
class Foo {
var number: Int = 0
}
class Bar {
fun run(consumer: (Int) -> Unit) {
repeat(5) {
consumer(it)
}
}
}