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 {
- 如何实现一个延迟加载recyclerView适配器,像使用kotlin的realm recyclerView适配器
- “kotlin-noarg”插件在Realm中不起作用
- Kotlin – 如何使外部类只读字段
- Android的测试在领域的kotlin
- 错误:Parceler:无法找到类型io.realm.RealmList的读/写生成器
- Kotlin和@Transient
- Realm&Kotlin:DefaultRealmModuleMediator.java – > error:unreachable statement
- 错误:包含非法的最终字段-Kotlin
- 无法在RealmObject子类中创建ArrayList