讨论了Scala中可能的标识符。事实证明你可以定义变量+
这有用吗?我似乎无法用它做任何事情:
felix@felix-UX32VD:~$ scala
Welcome to Scala version 2.9.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_21).
Type in expressions to have them evaluated.
Type :help for more information.
scala> var + = 42
+: Int = 42
scala> +
|
|
You typed two blank lines. Starting a new command.
scala> List(+,+,+)
<console>:1: error: illegal start of simple expression
List(+,+,+)
^
scala> (+)
<console>:1: error: illegal start of simple expression
(+)
^
scala>
我理解它对于函数定义很有用,即运算符重载,但似乎Scala支持原始表达式并尝试解析它。
对于id +?
的vars或val有什么用处吗?