I'm a bit rusty with protocol composition in Kotlin, I'd just like to combine multiple interfaces by declaring a custom typealias
:
// This doesn't work
typealias MyType = (ReadableInterface && WritableInterface)
Any ideas?
In Swift, I would do it this way:
typealias MyType = ReadableInterface & WritableInterface
In Objective C, I would do it this way:
typedef <ReadableInterface, WritableInterface> MyType;
A class in Kotlin can implement as many interfaces as they like but it can only extend from one abstract class.
Typealias usage in multi-platform projects To make this easier, Kotlin provides a mechanism of expected and actual declarations. The interfaces in the common code are the expected declarations, defined using the expect keyword. The implementation in the platform code is defined using the actual keyword.
Why not just create new interface?
interface MyType : ReadableInterface, WritableInterface
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With