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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With