我有一个关于Kotlin构造器的问题。
class abc {
constructor(a: Int)
constructor(a: Int, e: Int)
}
class def(a: Int) {
constructor(a: Int, e: Int) : this(a)
}为什么我需要在def类中调用这个(A)?
abc类和def类有什么不同??
发布于 2017-12-26 21:11:53
第一个类没有主构造函数,而第二个类有一个。根据documentation for ,你必须委托给它。
如果类有一个主构造函数,则每个辅助构造函数都需要直接或间接地通过另一个辅助构造函数委托给主构造函数。委托给同一类的另一个构造函数是使用
this关键字:
https://stackoverflow.com/questions/47979047
复制相似问题