Kotlin的型变解析(协变、逆变和不变)
一、首先来看一个例子 import java.util.* /** * @author:wangdong * @description:型变 */ fun main(args: Array<String>) { } /** * 定义一个类,实现了List接口 * 协变out(返回值只读类型),逆变in(通常是写入的),可读可写就是不变了 */ class MyLisøt<in E>{ val size: Int get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. fun contains(element: @UnsafeVariance E): Boolean { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } fun contai...