Scala Syntax- 문자열을 객체로 전달합니다
문제
Scala의 Regexps와 함께 놀면서 나는 다음과 같은 것을 썼습니다.
scala> val y = "Foo"
y: java.lang.String = Foo
scala> y "Bar"
scala>
보시다시피, 두 번째 진술은 조용히 받아 들여집니다. 이것은 법적 진술입니까? 그렇다면 어떻게해야합니까? 아니면 파서의 버그입니까? 오류 메시지가 있어야합니까?
해결책
이것은 실제로 파서의 오류입니다. 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"
^
제휴하지 않습니다 StackOverflow