我有一个课程如下
class Employee(var person: String = "Employee", var worksAt: String = "California", var mood: String = "Happy") {
var name: String = "Name: "
set(value){
name = "Name: $value"
}
var allString: String
private set
init {
this.allString = "$name works at $worksAt is $mood"
this.person = "Person: " + person!!
this.worksAt = "Work at: " + worksAt
this.mood = "Mood :" + mood
}
override fun toString(): String {
return this.name + "\n" + worksAt + "\n" + mood
}
}
当我设置名称
时 val reaEmployee = Employee()
reaEmployee.name = edt_main.text.toString()
名称以无限递归方式设置...即获取Name: Name: .... $value
...直到内存不足。我设置错误了什么?
答案 0 :(得分:7)