可能重复:
从java访问scala对象字段
我有这个 scala 对象
object Foo {
val TOTAL = 10
def totalMethod = 10
}
当我在java代码上这样做时:
System.out.println(Foo.totalMethod());
它有效,但是当我这样做时
System.out.println(Foo.TOTAL);
它没有:
[error] /Users/pfernand/Projects/foo/Whatever.java:23: cannot find symbol
[error] symbol : variable TOTAL
[error] location: class Foo
[error] System.out.println(Foo.TOTAL);
[error]