在Scala中使用regexp时,我写了类似这样的内容:
scala> val y = "Foo"
y: java.lang.String = Foo
scala> y "Bar"
scala>
如您所见,第二个声明只是默默接受。这是合法的法律声明,如果是,它的作用是什么?或者它是解析器中的错误,应该有错误消息?
答案 0 :(得分: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"
^