定义类的时候如果不声明val 和 var,scala不会警告和报错
scala> class User(age: Int, id: Int, name: String)
defined class User
scala> val userno1=new User(18, 1," dong")
userno1: User = $iwC$$iwC$User@779b2f8b
也不会报错
scala> userno1.age
<console>:23: error: value age is not a member of User
userno1.age
^
但是当调用userno1的age 的时候报错了:
value age is not a member of User
正确的方法当然是:
scala> class User(var age: Int, var id: Int, var name: String)
defined class User
scala> val userno2=new User(29, 2, "Li")
userno2: User = $iwC$$iwC$User@13d50885
scala> userno2.age
res35: Int = 29