我最近在研究 kotlin 泛型,但我发现了一些奇怪的情况
interface MyItem
fun <ITEM : MyItem> bindItem(items: List<ITEM>?) {
val castedItem = items as List<MyItem>?
}
fun <ITEM : MyItem> bindItem2(items: MutableList<ITEM>?) {
val castedItem = items as MutableList<MyItem>?
}
Run Code Online (Sandbox Code Playgroud)
只有在 MutableList 情况下,编译器才会警告未经检查的 Cast
如果有人知道这种情况,请告诉我。