检查Kotlin对象列表中的泛型类型

时间:2017-10-11 17:10:38

标签: generics kotlin

有一个Kotlin对象列表(这里是ModelTrap),它们使用各种数据模型进行参数化。我需要能够循环遍历它们并使用与为此checkTraps方法提供的模型具有相同类型参数化的那些。

//val trapList: MutableList <ModelTrap <*>> = mutableListOf()
inline fun <reified T> checkTraps(model : T) {

    for (trap in trapList) {
        if (trap is ModelTrap <T>) { // "Cannot check for instance of erased type."
            trap.catch(model)
        }
    }
}

...但是我一直试图弄清楚如何做到这一点。有没有更好的方法来定义该列表?有没有办法检查类型T的实例?

0 个答案:

没有答案
相关问题