/** * Created by common on 17-4-19. */ object Assert {
def main(args: Array[String]): Unit = { val a = new Assert() a.above1(0)
}
}
class Assert { val value = 1
def above(that: Int): Unit = { val thatVal = that val thisVal = this.value //如果条件不满足,Exception in thread "main" java.lang.AssertionError: assertion failed assert(thatVal == thisVal) }
//另一种断言 //如果条件不满足,Exception in thread "main" java.lang.AssertionError: assertion failed def above1(that: Int): Unit = { { val thatVal = that val thisVal = this.value } ensuring(that == this.value)