Scala Postfix 运算符警告与 Scaladoc 相矛盾

Scala Postfix operator warning contradicts with Scaladoc

我的代码: val exitStatus = url #> outfile !

scala.sys.process: new URL("http://www.scala-lang.org/") #> new File("scala-lang.html") !

警告:

postfix operator ! should be enabled
[warn] by making the implicit value scala.language.postfixOps visible.
[warn] This can be achieved by adding the import clause 'import scala.language.postfixOps'
[warn] or by setting the compiler option -language:postfixOps.
[warn] See the Scaladoc for value scala.language.postfixOps for a discussion
[warn] why the feature should be explicitly enabled.
[warn]     val exitStatus = url #> outfile !
[warn]                                     ^
[warn] one warning found

卧槽???

保持冷静并遵守警告。

import scala.language.postfixOps
...
val exitStatus = url #> outfile !
...

而且...没有警告! :)

这样做的原因是,Scala 的新手不会无意中使用它们而最终对语法更加困惑。我不确定我是否同意这个理由,但它似乎适用于我的 coworkers/friends,所以肯定有一些东西。


顺便提一句 here 是 Scaladoc 页面,其中详细介绍了所有这些内容。您还可以将它们作为编译器标志或通过 build.sbt.

启用
-language:dynamics             # Allow direct or indirect subclasses of scala.Dynamic
-language:existential          # Existential types (besides wildcard types) can be written and inferred
-language:experimental.macros  # Allow macro defintion (besides implementation and application)
-language:higherKinds          # Allow higher-kinded types
-language:implicitConversions  # Allow definition of implicit functions called views
-language:postfixOps           # Allow postfix operator notation, such as `1 to 10 toList'
-language:reflectiveCalls      # Allow reflective access to members of structural types