Possible Duplicate:
Scala operator oddity
I'm very new to Scala and I read that in this language everything is an Object, cool. Also, if a method has only 1 argument, then we can omit the '.' and the parentesis '( )', that's ok.
So, if we take the following Scala example: 3 + 2
, '3' and '2' are two Int
Objects and '+' is a method, sounds ok. Then 3 + 2
is just the shorthand for 3.+(2)
, this looks very weird but I still get it.
Now let's compare the following blocks on code on the REPL
:
scala> 3 + 2
res0: Int = 5
scala> 3.+(2)
res1: Double = 5.0
What's going on here? Why does the explicit syntax return a Double
while the shorthand returns an Int
??