Overloading Unary Operators in Scala PRO

When overloading an unary operators in Scala we should precede the operator name with ‘unary_’. Not doing so we will get an exception when using it. The following code sample shows that. package il.ac.hit.samples object Program { def main(args: Array[String]) { val ob = new RationalNumber(1,3) val other = -ob println(other) } } class RationalNumber(a:Int,b:Int) […]

Skip to content Update cookies preferences