class Rational(n: Int, d: Int) {
require(d != 0)
override def
toString = n +"/"+ d
}
The require method takes one boolean parameter. If
the passed value is
true, require will return normally. Otherwise, require
will prevent the ob-
ject from being constructed by throwing an
IllegalArgumentException .
原文地址:http://www.cnblogs.com/briller/p/3725768.html