android - 如何获得 KProperty<*>?
问题描述
这是代码:
1. private val dataStore: Lazy<ReadOnlyProperty<Context, DataStore<Preferences>>> = lazy {
preferencesDataStore(Objects.DATA_STORE_NAME)
}
2. val dataStoreValue: ReadOnlyProperty<Context, DataStore<Preferences>> = dataStore.value
3. val dataStoreGotValue: DataStore<Preferences> = dataStoreValue.getValue(requireContext(), "what it wants?")
第 3 点导致问题“Type mismatch.Required:KProperty<*> Found:String”
我试过这样做:“val prop: KProperty<*> = object : KProperty {...
override fun call(vararg args: Any?): String {return "ok"}
override fun callBy(args: Map<KParameter, Any?>): String { return "ok"}
}”,它确实有效,但它会导致过多的冗余代码。
有没有办法接收一些随机的 KProperty<*> 塞进“dataStoreValue.getValue”的嘴里,最终得到我的 DataStore,它已经存在了?
解决方案
推荐阅读
- powershell - 从 azure deploy 任务授予对 datafactory 的 keyvault 访问权限
- java - 我们可以在任何测试类中使用在 testng 监听器中定义的变量吗?
- arrays - 复制转置粘贴在空白处垂直打断
- c - 无法识别 tcl 库的代码块
- google-compute-engine - 在 GCP 上清理磁盘的脚本
- azure - 有没有办法从 Application Insights 导出 Log Analytics 查询历史记录?
- java - 将 ms 访问列返回到数组中
- android - 如何实现 LiveData Singleton
- bash - 将 shell 变量传递到 awk 搜索模式的开头
- c++ - 我的 cmake 项目中的“未定义引用”错误