5

在 Scala 中玩正则表达式时,我写了如下内容:

scala> val y = "Foo"
y: java.lang.String = Foo

scala> y "Bar"

scala>

如您所见,第二个语句只是默默接受。这是合法的法律声明吗?如果是,它有什么作用?或者它是解析器中的错误并且应该有错误消息?

4

1 回答 1

5

这确实是解析器中的错误。它在 scala 2.7.2 中修复(目前是 RC6)

$ ./scala
Welcome to Scala version 2.7.2.RC6 (Java HotSpot(TM) Client VM, Java 1.5.0_16).
Type in expressions to have them evaluated.
Type :help for more information.
scala> def y = "foo"
y: java.lang.String

scala> y "bar"
<console>:1: error: ';' expected but string literal found.
       y "bar"
         ^

scala> val x = "foo"
x: java.lang.String = foo

scala> x "foo"
<console>:1: error: ';' expected but string literal found.
       x "foo"
         ^

scala> "foo" "bar"
<console>:1: error: ';' expected but string literal found.
       "foo" "bar"
             ^
于 2008-11-02T11:50:49.230 回答