Kotlin 中的"!!"运算符是什么意思?



我正在阅读谷歌Android版的这本指南,他们有下面的片段。

!!userDao.save(response.body()!!)中做什么?

private fun refreshUser(userId: String) {
// Runs in a background thread.
executor.execute {
// Check if user data was fetched recently.
val userExists = userDao.hasUser(FRESH_TIMEOUT)
if (!userExists) {
// Refreshes the data.
val response = webservice.getUser(userId).execute()
// Check for errors here.
// Updates the database. The LiveData object automatically
// refreshes, so we don't need to do anything else here.
userDao.save(response.body()!!)
}
}
}

用于将表达式转换为非null,并在结果为null时抛出KotlinNullPointerException。因此,在这种用法中,它只会保存响应的主体不是null,否则将引发异常。

请参阅此处了解更多信息。

最新更新