I know about Kotlin's functional interfaces / SAM,...
# general-advice
p
I know about Kotlin's functional interfaces / SAM, though I might need to use the function type on different methods of the same class with different type parameters.
s
Theoretically if you want to port 1:1 your TS sample you could use typealiases like this:
Copy code
typealias MyFunctionType = () -> Unit

interface MyInterface {
    val foo: MyFunctionType
}
sample usage:
Copy code
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 🙂
👍 1
1
🙏 1
❤️ 1