gpt4 book ai didi

android - Kotlin 抽象类二级构造函数

转载 作者:行者123 更新时间:2023-11-29 14:26:10 25 4
gpt4 key购买 nike

我无法为这个抽象类创建辅助构造函数。

@SuppressLint("StaticFieldLeak")
abstract class BaseAndroidViewModel(
application: Application,
private val creditsGetByIdUseCase: CreditsGetByIdUseCase,
private val videosGetByIdUseCase: VideosGetByIdUseCase,
private val reviewGetByIdUseCase: ReviewGetByIdUseCase,
private val addToFavoritesUseCase: AddToFavoritesUseCase,
private val getFavoriteByIdUseCase: GetFavoriteByIdUseCase
) : AndroidViewModel(application) {

constructor(application: Application) : this(application) // There's a cycle in the delegation calls chain error

最佳答案

你可以像这样调用辅助构造函数 -

@SuppressLint("StaticFieldLeak") abstract class BaseAndroidViewModel : AndroidViewModel{
constructor(application: Application,
creditsGetByIdUseCase: CreditsGetByIdUseCase,
videosGetByIdUseCase: VideosGetByIdUseCase,
reviewGetByIdUseCase: ReviewGetByIdUseCase,
addToFavoritesUseCase: AddToFavoritesUseCase,
getFavoriteByIdUseCase: GetFavoriteByIdUseCase) : super(application)

constructor(application: Application) : super(application) }

关于android - Kotlin 抽象类二级构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54087586/

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