據我所知,在斯卡拉管道符的使用應相當於一個方法的調用。所以:斯卡拉「一」 + _.toString沒有表現得像「一個」。+(_。的toString)
scala> "a" + 3.toString
res0: java.lang.String = a3
是一樣的:
scala> "a".+(3.toString)
res1: java.lang.String = a3
我碰到這個地方沒有發生,當有一個佔位符的時機來了。我正在做更復雜的東西,但它可以蒸餾到:
scala> def x(f:(Int)=>String) = f(3)
x: (f: Int => String)String
scala> x("a" + _.toString)
res3: String = a3
到目前爲止好。但...
scala> x("a".+(_.toString))
<console>:9: error: missing parameter type for expanded function ((x$1) => x$1.toString)
x("a".+(_.toString))
這裏有什麼區別?我錯過了什麼?
霍爾迪
的[斯卡拉的foreach奇怪的行爲(http://stackoverflow.com/questions/2173373/scala-foreach-strange-behaviour) – sschaef
那麼可能重複, _answer_是重複的,但是怎麼會有人知道這個問題呢?我認爲這個問題的答案應該把相關的問題聯繫起來,而不是關閉問題本身。 –