楼主: zli08
10489 55

Beginning Scala 2nd Edition [推广有奖]

21
chitchatla 发表于 2015-5-6 19:32:50 |只看作者 |坛友微信交流群
  1. Listing 3-21. Implementing case features in a class on its own
  2. classStuff(val name: String,valage: Int) {
  3. overridedeftoString = "Stuff("+name+","+age+")"
  4. overridedefhashCode= name.hashCode+ age
  5. overridedefequals(other: AnyRef)= othermatch {
  6. case s: Stuff=> this.name== s.name &&this.age == s.age
  7. case _ => false
  8. }
  9. }
  10. objectStuff {
  11. defapply(name: String, age: Int) = newStuff(name,age)
  12. defunapply(s: Stuff)= Some((s.name, s.age))
  13. }
复制代码

使用道具

22
setecastro 发表于 2015-5-6 20:37:46 |只看作者 |坛友微信交流群
  1. Listing 3-22. Using def in the value class
  2. class SomeClass(val i: Int) extends AnyVal {
  3. def twice() = i*2
  4. }
  5. Here SomeClass is a user-defined value class that wraps the Int parameter and encapsulates a twice
  6. method. To invoke the twice method, create the instance of the SomeClass class as follows:
  7. scala> val v = new SomeClass(9)
  8. v: SomeClass = SomeClass@9
  9. scala> v.twice()
  10. res5: Int = 18
复制代码

使用道具

23
江南士族 发表于 2015-5-6 20:56:26 |只看作者 |坛友微信交流群
看看吧

使用道具

24
baijunde 发表于 2015-5-6 23:46:24 |只看作者 |坛友微信交流群
谢谢楼主分享

使用道具

25
wuzubin123 发表于 2015-5-7 21:47:51 |只看作者 |坛友微信交流群
谢谢分享

使用道具

26
Nicolle 学生认证  发表于 2015-6-18 11:07:07 |只看作者 |坛友微信交流群
提示: 作者被禁止或删除 内容自动屏蔽

使用道具

27
Nicolle 学生认证  发表于 2015-6-18 11:09:58 |只看作者 |坛友微信交流群
提示: 作者被禁止或删除 内容自动屏蔽

使用道具

28
Nicolle 学生认证  发表于 2015-6-18 11:13:00 |只看作者 |坛友微信交流群
提示: 作者被禁止或删除 内容自动屏蔽

使用道具

29
Nicolle 学生认证  发表于 2015-6-18 11:16:17 |只看作者 |坛友微信交流群
提示: 作者被禁止或删除 内容自动屏蔽

使用道具

30
Nicolle 学生认证  发表于 2015-6-18 11:17:56 |只看作者 |坛友微信交流群
提示: 作者被禁止或删除 内容自动屏蔽

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加JingGuanBbs
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-24 09:56