我正在研究Java / Scala中用于分析Java代码的项目。在我的scala代码中,我有:
package p{
object NodeKind{
// In real code they are not Int but this is good enough for the example
val `class` = 0
val interface = 0
}
}
我需要从Java访问它
class MyJavaClass{
void m(){
/* ... */
int value = p.NodeKind.//how can I access to `class` or interface ?
/* ... */
}
}
现在我已经解决了Brian Agnew解决方案,我添加了一个字段
val classKind = `class`
在我的scala对象中,我可以在我的java代码中使用p.nodeKind.classKind()
访问它,但我真的更喜欢知道`class`的编译(mangling?)规则和直接访问它的接口。
答案 0 :(得分:0)
我怀疑你的两个选择可能是:
e.g。
class A {
val class = 1
def clazz = class
}