CapturedTypeConstructor(*)不是RealmModel的子类型
我有以下方法可以得到Realm对象的新键。 我想能够通过类作为参数:
private fun getNextKeyForObject(myClass: Class<*>): Int { mRealm?.let { val maxId = it.where(myClass).max("id") if (maxId != null) { return it.where(myClass).max("id").toInt() + 1 } } return 0 }
我得到以下错误:
Type parameter bound for E in fun <E : RealmModel!> where(clazz: Class<E!>!): RealmQuery<E!>! is not satisfied: inferred type CapturedTypeConstructor(*) is not a subtype of RealmModel!
您需要指定generic upper bound
(请参阅https://kotlinlang.org/docs/reference/generics.html#upper-bounds ):
private fun <T : RealmModel> getNextKeyForObject(myClass: Class<T>): Int {