Scala Postfix 运算符警告与 Scaladoc 相矛盾 [英] Scala Postfix operator warning contradicts with Scaladoc
问题描述
我的代码:val exitStatus = url #>输出文件!
保持冷静并遵循警告.
import scala.language.postfixOps...val exitStatus = url #>外档!...
而且……没有警告!:)
这样做的原因是为了让 Scala 新手不会偶然使用它们,并最终对语法更加困惑.我不确定我是否同意这个理由,但它似乎适用于我的同事/朋友,所以肯定有它的意义.
<小时>另外这里是Scaladoc页面详细说明了所有这些.您还可以将这些作为编译器标志或通过 build.sbt
启用.
-language:dynamics # 允许 scala.Dynamic 的直接或间接子类-language:existential # 可以编写和推断存在类型(除了通配符类型)-language:experimental.macros # 允许宏定义(除了实现和应用)-language:higherKinds # 允许更高级的类型-language:implicitConversions # 允许定义称为视图的隐式函数-language:postfixOps # 允许后缀运算符表示法,例如`1 to 10 toList'-language:reflectiveCalls # 允许反射访问结构类型的成员
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???
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
这篇关于Scala Postfix 运算符警告与 Scaladoc 相矛盾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!