Typealias - Combine Multiple Interfaces in Kotlin

拜拜、爱过 提交于 2021-01-27 13:00:33

问题


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; 

回答1:


Why not just create new interface?

interface MyType : ReadableInterface, WritableInterface


来源:https://stackoverflow.com/questions/59044121/typealias-combine-multiple-interfaces-in-kotlin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!