The Scala programmer should have known this kind of entry:
class Person{ var id = 0 } var p = new Person p.id p.id = 2
equally
class Person{ private var _id = 0 def id = _id def id_=(i: Int) = _id = i } val p = new Person p.id
. But if you comment on the getter def id = _id
, p.id = 2
will result in a compilation error saying
error: value key is not a member of Person
Can anyone explain why?
source share