new F-6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 08:14:57 26 4
gpt4 key购买 nike

我的代码:val exitStatus = url #> 输出文件!

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

什么鬼???

最佳答案

enter image description here

保持冷静并遵守警告。

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

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

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


题外话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

关于Scala Postfix 运算符警告与 Scaladoc 相矛盾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39093695/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com