观看讲座4.2马丁·奥德斯基的斯卡拉当然,我不明白下面的类,或者它的用途:解释一个scala类和对象?
abstract class Boolean {
def ifThenElse[T](t: => T, e: => T): T
def && (x: => Boolean): Boolean = ifThenElse(x, False)
def || (x: => Boolean): Boolean = ifThenElse(True, x)
def unary_! : Boolean = ifThenElse(False , True)
def == (x: Boolean): Boolean = ifThenElse(x, x.unary_!)
def != (x: Boolean): Boolean = ifThenElse(x.unary_! , x)
object False extends Boolean {
def ifThenElse[T](t: => T, e: => T) = e
}
object True extends Boolean {
def ifThenElse[T](t: => T, e: => T) = e
}
}
可来样implentations /解释是提供这样我就可以更好地提供什么正在发生和/或它的使用?
谢谢,((!False)怎么叫方法'unary_!' ,是'!'和'unary_!'没有不同的方法签名? – 2013-04-22 14:42:27
@ user470184'unary_'是一种语言功能。请参阅Scala的语言规范或书籍,例如http://www.artima.com/pins1ed/basic-types-and-operations.html#5.3 – 2013-04-22 16:41:31