问题
My code:
val exitStatus = url #> outfile !
scala.sys.process:
new URL("http://www.scala-lang.org/") #> new File("scala-lang.html") !
Warning:
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???
回答1:
Keep calm and follow the warning.
import scala.language.postfixOps
...
val exitStatus = url #> outfile !
...
And... no warning! :)
The reason for these is so that people new to Scala don't use these by accident and end up more confused about syntax. I'm not sure I agree with this rationale, but it seems to work with my coworkers/friends, so there's definitely something to it.
As an aside here is the Scaladoc page that details all of these. You can also enable these as compiler flags or through 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
来源:https://stackoverflow.com/questions/39093695/scala-postfix-operator-warning-contradicts-with-scaladoc