gpt4 book ai didi

android - 如何从构造函数获取参数?

转载 作者:行者123 更新时间:2023-12-02 12:41:17 24 4
gpt4 key购买 nike

class AlmatyJobViewModel(application: Application) : AndroidViewModel(application){   

fun clearSuggestionsHistory(){
SearchRecentSuggestions(application, MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE)
.clearHistory()
}
}

Unresolved Referense: application



如果要在此方法中使用它,如何从构造函数中获取应用程序?

最佳答案

如果添加private val application,则会在编译时出现异常,例如

Accidental override: The following declarations have the same JVM signature



因此,要解决此问题,只应在需要的地方调用 getApplication()
SearchRecentSuggestions(getApplication(), MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE).clearHistory()

关于android - 如何从构造函数获取参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58714244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com