2 ms·
Scala doesn't have operator overloading technically. It had two orthogonal language features that give rise to operators: 1. Methods can use symbols 2. Single
by whateveracct 10y ago
Scala doesn't have operator overloading technically. It had two orthogonal language features that give rise to operators:
1. Methods can use symbols
2. Single-arg methods can be called infix
Scala doesn't have operator precedence rules. All operators (infix methods really) are left associative unless they end in a colon in which case they are right associative. Examples
2 + 1
Is
2.+(1)
2 :: 1 :: Nil
Is
Nil.::(1).::(2)
The colon thing is the sort of thing that on paper seems hacky but in practice Just Works and is seldom used. But when you do use it it really helps a lot.
- cottonseed 10y ago> Scala doesn't have operator precedence rules. That's not true. The operator precedence is determined by the first character of the operator: (all letters) | ^ & < > = ! : + - * / % (all other special characters) Precedence is different than associativity.