Let's say I have a iOS and Android version of a library
They provide two simple classes:
Swift:
class SwiftVersionOfSomething {
fun test(): String {
return "hi"
}
}
Android:
abstract class KotlinVersionOfSomething {
func test(): String {
return "hi"
}
}
I need the value of X on both, so in my common module I create. I have no control how they are instantiated and purely just need to access the x value for both
It would be useful if I could do something like
expect <Object_With_function> SharedVersionOfSomething {
fun test(): String
}
actual typealias SharedVersionOfSomething = KotlinVersionOfSomething
actual typealias SharedVersionOfSomething = SwiftVersionOfSomething
So basically, we just say we need some object of any type that has a particular function / variable regardless of type (class/abstract class/data class/object)