class X {
fun someFunc(x: Int, y: String, z: Double) {
println("x = [$x], y = [$y], z = [$z]")
}
}
fun main(args: Array<String>) {
val func = X::someFunc
val instance = X()
func.call(instance, 1, "Hi", 123.45)
}
Given the code above how can I convert it to a function with instance built-in so when calling I can just pass the params without instance
? (I could just use X()::someFunc
but that's not the point of this question)
You could just implement a delegate wrapping that logic. Example implementation:
And then use it like this (example based on the code in question):
func.withInstance(instance).call(1, "Hi", 123.45)