Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding spaces to the + operator in Scala gives different results?

Tags:

scala

Scala newbie here

Trying

(1).+(2) returns a Int value of 3, so far so good
but
1.+(2) returns a Double value of 3.0.

But if you do
1 . +(2) it returns a Int value of 3.
Note: The only difference between this and the above is the space after the "1"

Does Spaces matter in Scala? Im more curious as to how 1.+(2) returned a Double as it looks like it parsed 1. as a Double and then added "2" to it.

like image 884
rajasaur Avatar asked Jun 10 '11 02:06

rajasaur


1 Answers

1.+(2) is calling the + method on the Double "1.". This is a carry-over from Java syntax, where "1." is equivalent to 1.0.

like image 96
mpilquist Avatar answered Nov 03 '22 14:11

mpilquist