这些导入后为什么需要分号? [英] Why do I need semicolons after these imports?
问题描述
到目前为止,我从未真正在Scala中使用Traits,我想改变它。我有这个代码:
I never really used Traits much in Scala so far, and I want to change this. I have this code:
import tools.nsc.io.Path
import java.io.File
trait ImageFileAcceptor extends FileAcceptor {
override def accept(f:File) = {
super.accept(f) match {
case true => {
// additional work to see if it's really an image
}
case _ => false
}
}
}
问题是,当我用 sbt
编译,我一直收到:
The problem is, when I compile with sbt
, I keep receiving:
ImageFileAcceptor.scala:2:' ;'预期但'导入'找到。
如果我在之后添加;
导入,代码编译。这是 FileAcceptor
:
If I add ;
after the imports, the code compiles. Here's FileAcceptor
:
import java.io.File
trait FileAcceptor extends Acceptable {
override def accept(f:File):Boolean = f.isFile
}
这里的可接受
:
import java.io.File
trait Acceptable {
def accept(f:File):Boolean
}
我不明白为什么我在进口后需要分号。
I don't understand why I need semicolons after the imports.
编辑:也许输出sbt很有用:
maybe the output of sbt is helpful:
[info] Building project tt 1.0 against Scala 2.8.1
[info] using sbt.DefaultProject with sbt 0.7.5 and Scala 2.7.7
推荐答案
当scala编译器遇到Macintosh行结尾 - \ r
时 - scala编译器将错误地声明需要分号,因为Moritz如此推断。 Scala参考手册的第1.2节描述了正确的换行符。我在参考文献中找不到哪些字符文字被视为换行符。根据经验,Windows( \\\\ n
)和Unix( \ n
)都可以接受。据推测,scala在这方面与Java严格兼容。
When the scala compiler encounters a Macintosh line ending--being \r
--the scala compiler will erroneously declare the need for a semi-colon, as Moritz so deduced. Section 1.2 of the Scala Reference Manual describe correct newline characters. I could not find in the Reference which character literals were considered as newlines. From experience, both Windows (\r\n
) and Unix (\n
) are acceptable. Presumably scala is strictly compatible with Java in this regard.
这篇关于这些导入后为什么需要分号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!