我的代码:
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
WTF ???
答案 0 :(得分:7)
保持冷静并遵循警告。
import scala.language.postfixOps
...
val exitStatus = url #> outfile !
...
而且......没有警告! :)
这样做的原因是,Scala的新手不会意外地使用这些并最终对语法更加困惑。我不确定我同意这个理由,但它似乎与我的同事/朋友一起工作,所以肯定会有一些东西。
旁边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