I'm reading Programming in Scala by M. Odersky and now I'm trying to understand the meaning of operators. As far as I can see, any operator in Scala is just a method. Consider the following example:
class OperatorTest(var a : Int) { def +(ot: OperatorTest): OperatorTest = { val retVal = OperatorTest(0); retVal.a = a + ot.a; println("=") return retVal; } } object OperatorTest { def apply(a: Int) = new OperatorTest(a); } I this case we have only + operator defined in this class. And if we type something like this:
var ot = OperatorTest(10); var ot2 = OperatorTest(20); ot += ot2; println(ot.a); then
=+ 30 will be the output. So I'd assume that for each class (or type?) in Scala we have += operator defined for it, as a += b iff a = a + b. But since every operator is just a method, where the += operator defined? Maybe there is some class (like Object in Java) containing all the defenitions for such operators and so forth.
I looked at AnyRef in hoping to find, but couldn't.