0

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??

4

1 に答える 1

7

3.ですDouble。レクサーが最初にそこに到達します。試してみてください(3).+(2)

于 2012-08-10T21:22:59.657 に答える