plantleaf
02/12/2024, 9:35 AMSzymon Jeziorski
02/12/2024, 11:51 AMtypealias MyFunctionType = () -> Unit
interface MyInterface {
val foo: MyFunctionType
}
sample usage:
class MyInterfaceImplementation(private val name: String) : MyInterface {
override val foo: MyFunctionType = {
println("within implementation: $name")
}
}
val first = MyInterfaceImplementation("first")
val second = MyInterfaceImplementation("second")
first.foo() // within implementation: first
second.foo() // within implementation: second
But to be fair, I have never used this kind of approach myself in Kotlin.
It would be helpful if you could explain the actual use case you're trying to solve, as I think we might be having XY problem here 🙂