admin管理员组文章数量:1122832
If you try to use a postfix operator, you get an error with an explanation:
scala> Seq(1, 2, 3) reverse
^
error: postfix operator reverse needs to be enabled
by making the implicit value scala.language.postfixOps visible.
This can be achieved by adding the import clause 'import scala.language.postfixOps'
or by setting the compiler option -language:postfixOps.
See the Scaladoc for value scala.language.postfixOps for a discussion
why the feature needs to be explicitly enabled.
In particular, it says:
See the Scaladoc for value scala.language.postfixOps for a discussion
Where is this discussion? When I look at the 2.13 scaladocs entry for postfixOps
and its companion objects, they have no discussion or explanation for the existence of this trait/object:
And the companion object:
If you try to use a postfix operator, you get an error with an explanation:
scala> Seq(1, 2, 3) reverse
^
error: postfix operator reverse needs to be enabled
by making the implicit value scala.language.postfixOps visible.
This can be achieved by adding the import clause 'import scala.language.postfixOps'
or by setting the compiler option -language:postfixOps.
See the Scaladoc for value scala.language.postfixOps for a discussion
why the feature needs to be explicitly enabled.
In particular, it says:
See the Scaladoc for value scala.language.postfixOps for a discussion
Where is this discussion? When I look at the 2.13 scaladocs entry for postfixOps
and its companion objects, they have no discussion or explanation for the existence of this trait/object:
And the companion object:
Share Improve this question asked Nov 21, 2024 at 19:46 Cory KleinCory Klein 55.4k47 gold badges203 silver badges259 bronze badges 1 |1 Answer
Reset to default 3The right place to look at is scala.language.postfixOps
.
Only where this feature is enabled, is postfix operator notation (expr op) permitted. If postfixOps is not enabled, an expression using postfix notation is rejected by the compiler.
Why keep the feature? Postfix notation is preserved for backward compatibility only. Historically, several DSLs written in Scala need the notation.
Why control it? Postfix operators interact poorly with semicolon inference. Most programmers avoid them for this reason alone. Postfix syntax is associated with an abuse of infix notation, a op1 b op2 c op3, that can be harder to read than ordinary method invocation with judicious use of parentheses. It is recommended not to enable this feature except for legacy code.
本文标签: scaladocWhere is the documentation for scalalanguagepostfixOpsStack Overflow
版权声明:本文标题:scaladoc - Where is the documentation for scala.language.postfixOps? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307586a1933363.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
scala.languageFeature.postfixOps
were the only results I could get Google to show me. It's easy to miss that there's an extra wordFeature
in there and you need to go toscala.language.postfixOps
instead. – Cory Klein Commented Nov 21, 2024 at 20:38