我目前正在进入 Scala 并且想知道在调用以“:”结尾的方法时使用对象表示法的区别。由于以 ':' 结尾的方法名称通常会产生右侧关联性,因此在使用对象表示法调用此类方法时,这似乎会发生变化。
例子:
scala> 3 +: List(1,2)
res1: List[Int] = List(3, 1, 2)
scala> List(1,2) +: 3 // does not compile due to right side associativity
scala> (List(1,2)).+:(3)
res2: List[Int] = List( 3, 1, 2)
现在我不明白为什么使用对象表示法会禁用右关联功能。有人可以对此进行解释或链接到有关此问题的文档吗?