- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 35767 个
- 通用积分
- 31.6124
- 学术水平
- 6 点
- 热心指数
- 6 点
- 信用等级
- 2 点
- 经验
- 24460 点
- 帖子
- 213
- 精华
- 0
- 在线时间
- 628 小时
- 注册时间
- 2005-11-19
- 最后登录
- 2023-8-30
|
- Listing 3-21. Implementing case features in a class on its own
- classStuff(val name: String,valage: Int) {
- overridedeftoString = "Stuff("+name+","+age+")"
- overridedefhashCode= name.hashCode+ age
- overridedefequals(other: AnyRef)= othermatch {
- case s: Stuff=> this.name== s.name &&this.age == s.age
- case _ => false
- }
- }
- objectStuff {
- defapply(name: String, age: Int) = newStuff(name,age)
- defunapply(s: Stuff)= Some((s.name, s.age))
- }
复制代码
|
|