What would be the use of having an `expect/actual`...
# multiplatform
j
What would be the use of having an
expect/actual
Interface in Kotlin? I’m having a hard time wrapping my mind around how that would be useful.
j
having a supertype that only exists on a particular platform
having functions that only exist on a particular platform
using a typealias to a platform-specific type on a particular platform
k
In simple common can't have everything as platform dependency is huge. So we have expect actual. We expect something from common code like showToast and actual implements to every platform we're using. We need to code the actual function.
j
Yes but I am asking specifically about interfaces. Why would you want the contract of a class to be different in different platforms?
h
You can add more methods on a particular platform
But as a user this can be strange sometimes. For example ktor uses this pattern including a common helper method which creates the type, so you need to pass platform specific parameters which are unused on other platforms. So you should be careful about your public api.
👍 1