赞
踩
81. 简述 Kotlin 中泛型型变-协变、逆变、不变 ? |
Kotlin 中泛型引入了 in 和 out: 逆变(In) 如果你的类是将泛型对象作为函数的参数,那么可以用 in: interface Consumer { fun consume(item: T) } 可以称其为 consumer class/interface,因为其主要是消费指定泛型对象。 |
协变(Out) 如果你的类是将泛型 |
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。