Scala 中的运算符优先级 [英] Operator precedence in Scala

查看:30
本文介绍了Scala 中的运算符优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢 Scala 的运算符优先级建议,但在某些极少数情况下,未修改的规则可能不方便,因为您在命名方法时有限制.有没有办法在 Scala 中为类/文件等定义另一个规则?如果没有,以后会解决吗?

I like Scala's propose of operator precedence but in some rare cases, unmodified rules may be inconvenient, because you have restrictions in naming your methods. Are there ways to define another rules for a class/file, etc. in Scala? If not, would it be resolved in the future?

推荐答案

运算符优先级在 Scala 参考 - 6.12.3 中缀操作 运算符中的第一个字符.按优先级递增的顺序列出:

Operator precedence is fixed in the Scala Reference - 6.12.3 Infix Operations by the first character in the operator. Listed in increasing order of precedence:

(all letters)
|
^
&
= !
< >
:
+ -
* / %
(all other special characters)

而且改变的可能性不大.它可能会产生比它修复的更多的问题.如果您使用正常的运算符优先级,为一个类更改它会非常混乱.

And it's not very probable that it will change. It will probably create more problems than it fixes. If you're used the normal operator precedence changing it for one class will be quite confusing.

这篇关于Scala 中的运算符优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆