3

Many data types in scala, like HashMaps, have the postfix increment operator implemented, but Ints and Doubles have not.

Is it because if there was a postfix operator for numbers, there had to be a prefix operator too, and that would not fit the way operators are implemented in scala (as methods)?

4

2 回答 2

5

The ++ operator is not meant as an imperative increment operator, but as a union of two collection, such that it produces new collections instead of modifying either of the old ones.

于 2013-05-01T11:25:39.490 回答
2

The increment operator is a very imperatively styled thing. I think (!) as you're encouraged to program in a functional style, where variable values are not supposed to change in general, it is not present in Scala.

However, this is highly unofficially what I think from a Scala programmer point of view.

于 2013-05-01T10:36:04.810 回答