Kotlin 科特林二级建造师
我有一段导致错误的代码。我似乎找不到这个问题,因为我一直在看一本书。代码如下:Kotlin 科特林二级建造师,kotlin,constructor,Kotlin,Constructor,我有一段导致错误的代码。我似乎找不到这个问题,因为我一直在看一本书。代码如下: class Player (_name: String, var healthPoints: Int, val isBlessed: Boolean, private val isImmortal: Boolean) { var name = _name get() = field.capitalize
class Player (_name: String,
var healthPoints: Int,
val isBlessed: Boolean,
private val isImmortal: Boolean) {
var name = _name
get() = field.capitalize()
private set(value) {
field = value.trim()
}
constructor(name: String) : this(name,
healthPoints = 100,
isBlesed = true,
isImmortal = false)
Error:(14, 33) Kotlin: None of the following functions can be called with the arguments supplied:
public constructor Player(name: String) defined in com.bignerdranch.nyethack.Player
public constructor Player(_name: String, healthPoints: Int, isBlessed: Boolean, isImmortal: Boolean) defined in com.bignerdranch.nyethack.Player
我不理解这个关键字正在创建的错误,如下所示:
class Player (_name: String,
var healthPoints: Int,
val isBlessed: Boolean,
private val isImmortal: Boolean) {
var name = _name
get() = field.capitalize()
private set(value) {
field = value.trim()
}
constructor(name: String) : this(name,
healthPoints = 100,
isBlesed = true,
isImmortal = false)
Error:(14, 33) Kotlin: None of the following functions can be called with the arguments supplied:
public constructor Player(name: String) defined in com.bignerdranch.nyethack.Player
public constructor Player(_name: String, healthPoints: Int, isBlessed: Boolean, isImmortal: Boolean) defined in com.bignerdranch.nyethack.Player
您在单词
isBlesed
中有一个输入错误,您在最后三个参数中使用了关键字参数。试着不用它们。tbh,我不知道这为什么会导致Kotlin出现问题…显然,但这似乎意味着主构造函数是一个“非Kotlin函数”…别担心,我太傻了。这就是问题所在,谢谢!奇怪的是,我没有看到它,因为错误行在“this”这个词下面