首页 > 代码库 > Scala 学习笔记

Scala 学习笔记

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 .