Scala Postfix operator warning contradicts with Scaladoc

落爺英雄遲暮 提交于 2019-12-06 12:29:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!