commit | 424f130999646d9a3d067b05e2f1f386c614278f | [log] [tgz] |
---|---|---|
author | Vern Zheng <kevonzheng@gmail.com> | Wed Aug 12 16:29:59 2015 +0800 |
committer | Vern Zheng <kevonzheng@gmail.com> | Wed Aug 12 16:29:59 2015 +0800 |
tree | 9b5be7d3756531b751450581f1bf9fdfc20f7b37 | |
parent | 9cb6b3fe2615b4ca299a5ef3fbad997a990583c8 [diff] |
Update exercise02.scala
diff --git a/src/Chapter17/exercise02.scala b/src/Chapter17/exercise02.scala index 2376f56..35435a7 100644 --- a/src/Chapter17/exercise02.scala +++ b/src/Chapter17/exercise02.scala
@@ -1,6 +1,11 @@ /** * 定义一个可变类Pair[T],带一个swap方法,交换对偶中组件的位置。 */ -class Pair[T](val s:T,val t:T){ - def swap() = new Pair(t,s) +class Pair[T] (var s: T, var t: T) { + def swap() = { + val temp = s + this.s = t + this.t = temp + } + override def toString = s"s: $s, t: $t" }