https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
j

Jeff Lockhart

01/19/2021, 9:07 PM
Is it possible for an expect declaration to use an interface, where the actual implementation implements the interface signature? For example:
Copy code
// commonMain

expect class FooClass : BarInterface {
    fun fooFun()
}

interface BarInterface {
    fun barFun()
}

// androidMain

actual typealias FooClass = FooImpl

class FooImpl {
    fun fooFun() {}
    fun barFun() {}
}
I get the error on `typealias FooClass`:
Copy code
Actual typealias 'FooClass' has no corresponding expected declaration The following declaration is incompatible because some supertypes are missing in the actual declaration:
public final expect class FooClass : BarInterface defined in ...
FooImpl
is from a library, so it’s not a class I can modify. But I’m trying to simplify declaring the expect API, as there are several classes that have the same interface.
b

Barco

01/19/2021, 9:26 PM
Seems not possible - essentially it would be duck typing in Kotlin.
j

Jeff Lockhart

01/19/2021, 9:35 PM
That makes sense.
2 Views