Android 名为的方法。应用在kotlin中不起作用
我有这个方法:Android 名为的方法。应用在kotlin中不起作用,android,kotlin,Android,Kotlin,我有这个方法: import android.content.Context import android.content.SharedPreferences import com.xx.model.preferences.keys.BooleanPref import com.xx.model.preferences.keys.StringPref import javax.inject.Inject override fun saveBoolean(pref: BooleanPref, v
import android.content.Context
import android.content.SharedPreferences
import com.xx.model.preferences.keys.BooleanPref
import com.xx.model.preferences.keys.StringPref
import javax.inject.Inject
override fun saveBoolean(pref: BooleanPref, value: Boolean) {
sharedPreferences.edit().putBoolean(pref.key, value).apply()
}
我的编译器说:
e:/model/preferences/PreferencesManager.kt:(24,68):没有为参数“block”传递值
但是我的应用方法是来自共享参考而不是来自Kotlin的标准库
如何解决这个问题?thx您是否使用apply{}而不是apply()呢?我的项目中有类似的代码,它正确地解析了apply函数,所以应该是可行的。你运行的是什么版本的Kotlin和Android Studio?这只在这个项目中,在其他作品中。是否(24,68)与你发布的代码片段相对应?当按住
Control
并单击apply
时,看不到参数“block”
会发生什么?它显示了哪个函数的源?看到您的import
s部分也会很高兴。