有时,十六进制值中包含足够的字母字符,以至于Android Studio/Intellij中的Inspections算法错误地将它们识别为拼写错误.例如,它错误地将下面的"dfab"标识为拼写错误:
private static final String FOO = "6036aae7-9b4d-4ecd-a81f-dfab4b871039";
Run Code Online (Sandbox Code Playgroud)
我通常发现错字检查很有帮助所以我不想完全禁用它.我也不想抑制文件的拼写检查.此外,我不想在字典中添加"dfab",因为它不是一个有效的单词,我希望拼写检查器在其他上下文中标记它.
在这种情况下,有没有办法抑制Android Studio/IntelliJ中的拼写错误警告?
我正在运行Android Instrumentation测试,当我使用Contextreturn by InstrumentationRegistry.getContext()检索给定id的字符串时,我收到消息:
android.content.res.Resources$NotFoundException: String resource ID #0x7f060020
我从其他字符串资源尝试过ID,但无济于事.
我在stackoverflow上查看了有关同一个异常的几个问题,但所有这些都涉及将字符串id传递给View.setText.这对我来说无关紧要,因为我正在创建一个库而且根本没有View.
如何在react js中将对象转换为字符串
var numeroToken = this.getSearchParams();
getSearchParams(k){
var p={};
location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(s,k,v){p[k]=v})
return k?p[k]:p;
}
Run Code Online (Sandbox Code Playgroud)
我试图从 getSeatchParms() 获取 url,但它作为对象返回。如何将其转换为字符串?
我正在尝试使用 Kotlin Flows 和 Firebase 为我的视图提供实时更新。
这就是我从我的ViewModel以下收集实时数据的方式:
class MainViewModel(repo: IRepo): ViewModel() {
val fetchVersionCode = liveData(Dispatchers.IO) {
emit(Resource.Loading())
try {
repo.getVersionCode().collect {
emit(it)
}
} catch (e: Exception){
emit(Resource.Failure(e))
Log.e("ERROR:", e.message)
}
}
}
Run Code Online (Sandbox Code Playgroud)
这就是每当 Firebase 中的值发生变化时我从我的存储库中发出每个数据流的方式:
class RepoImpl: IRepo {
override suspend fun getVersionCodeRepo(): Flow<Resource<Int>> = flow {
FirebaseFirestore.getInstance()
.collection("params").document("app").addSnapshotListener { documentSnapshot, firebaseFirestoreException ->
val versionCode = documentSnapshot!!.getLong("version")
emit(Resource.Success(versionCode!!.toInt()))
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我使用:
emit(Resource.Success(versionCode!!.toInt()))
Run Code Online (Sandbox Code Playgroud)
Android Studio 突出显示了发出调用:
挂起函数“emit”只能从协程或其他挂起函数调用
但是我从CoroutineScope我的ViewModel.
这里有什么问题?
谢谢
android kotlin firebase kotlin-coroutines kotlinx.coroutines.flow
Kotlin 中具体化的类型参数可防止类型参数擦除并允许在运行时知道类型参数。这允许以下代码按预期编译和运行:
inline fun <reified T> isA(value: Any) = value is T
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用“T”作为类型参数而不是独立时,我收到一条消息,表明它是一个已删除的类型。以下代码演示了这一点,仅用于说明目的:
inline fun <reified T> isListOfA(name: String): Boolean {
val candidate = Class.forName(name)
return candidate is List<T>
}
Run Code Online (Sandbox Code Playgroud)
这是由于技术限制吗?如果是这样,那是什么限制?