```expect interface A { fun doSomething() }``` ...
# multiplatform
a
Copy code
expect interface A {
   fun doSomething()
}
Copy code
actual interface A {
   actual fun doSomething() { /*do sth. */ }
}
This code causes an error, because the expected function is abstract by default and the actual function has an implementation, which means that modality is different. Can I somehow define the expect function as non-abstract? Usually you would give a function of an interface a body to make it non-abstract. If you do that, the error at the actual declaration is gone, but expected declarations must not have bodies, so that's another error.
k
interfaces can't have implementations
is there a reason you want to use expect/actual on an interface?
a
@Kris Wong "Interfaces in Kotlin can contain declarations of abstract methods, _as well as method implementations._" from https://kotlinlang.org/docs/reference/interfaces.html#interfaces This feature is quite handy in my opinion. In the expect/actual context I just found a kinda hacky solution using an extension function:
Copy code
interface A
expect A.doSomething()
Copy code
actual A.doSomething() { ... }
k
huh... how did I not know that
too much Java on the brain i suppose
a
Java has 'default' interface methods