Kotlin 错误:无法使用提供的参数调用以下函数

Kotlin 错误:无法使用提供的参数调用以下函数,kotlin,Kotlin,我的班级: class Manager (var name: String, var nationality: String) { constructor(agent: String): this() {} } 返回以下错误: None of the following functions can be called with the arguments supplied. <init>(String) defined in Manager <init>(S

我的班级:

class Manager (var name: String, var nationality: String) {

    constructor(agent: String): this() {}
}
返回以下错误:

None of the following functions can be called with the arguments supplied.

<init>(String) defined in Manager
<init>(String, String) defined in Manager
使用提供的参数无法调用以下函数。
(字符串)在管理器中定义
管理器中定义的(字符串,字符串)

知道为什么吗?

您的类有一个接受两个参数的主构造函数,然后您定义一个接受一个参数的辅助构造函数

现在,根据Kotlin的说法:

如果类有一个主构造函数,则每个次构造函数 需要直接或间接委托给主构造函数 间接通过另一个二级构造函数

您试图通过调用
this()
来实现这一点,但由于您没有零参数构造函数(主构造函数或次构造函数),因此会导致编译错误

例如,要修复此问题,您可以从辅助构造函数调用主构造函数,如下所示:

class Manager (var name: String, var nationality: String) {
    constructor(agent: String): this(agent, "") {}
}

提示:什么构造函数是
this()
调用的?您能准确解释一下
this()
在这里做什么吗?我从教程中获取了代码。