如何将 `Class<Item>` 发送到 `ItemLiveData` class 构造函数?
How can I send `Class<Item>` to the `ItemLiveData` class constructor?
我有这个class:
class ItemLiveData<I>(private val classType: Class<I>): LiveData<I>() {
//I need to use classType
}
我还有另一个 class,我需要将自定义 class 传递给构造函数:
class MyRepository constructor() {
override fun getLiveData(): ItemLiveData<Item> {
return ItemLiveData(Class<Item>)
}
}
并且 Android 工作室抱怨:
Function invocation 'Class()' expected.
但是,如果我改变:
return ItemLiveData(Class<Item>)
收件人:
return ItemLiveData(javaClass)
我得到:
Type inference failed. Expected type mismatch:
required: ItemLiveData<Item>
found: ItemLiveData<MyRepository>
如何将 Class<Item>
发送到 ItemLiveData
class 构造函数?谢谢。
ItemLiveData(Class<Item>)
应该是 ItemLiveData(Item::class.java)
我有这个class:
class ItemLiveData<I>(private val classType: Class<I>): LiveData<I>() {
//I need to use classType
}
我还有另一个 class,我需要将自定义 class 传递给构造函数:
class MyRepository constructor() {
override fun getLiveData(): ItemLiveData<Item> {
return ItemLiveData(Class<Item>)
}
}
并且 Android 工作室抱怨:
Function invocation 'Class()' expected.
但是,如果我改变:
return ItemLiveData(Class<Item>)
收件人:
return ItemLiveData(javaClass)
我得到:
Type inference failed. Expected type mismatch:
required: ItemLiveData<Item>
found: ItemLiveData<MyRepository>
如何将 Class<Item>
发送到 ItemLiveData
class 构造函数?谢谢。
ItemLiveData(Class<Item>)
应该是 ItemLiveData(Item::class.java)