如何在java中使用反向引用的scala标识符?
我正在从事一个Java/Scala项目,该项目分析Java代码。在我的scala代码中,我有:如何在java中使用反向引用的scala标识符?,java,scala,interop,Java,Scala,Interop,我正在从事一个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{ v
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访问它,但我真的更想知道编译的混乱?“类”和接口直接访问的规则。我怀疑您的两个选项可能是: 在Scala类中创建访问器方法 使用反射在Java类中创建一个访问器方法来查找并读取该字段 e、 g
我认为他没有,是吗?@p3rand0r错了:你是对的,我犯了一个错误。根据你的建议,我在stackexchange上发布了qestion:在那里,他们告诉我这个问题真的属于这里:s
class A {
val class = 1
def clazz = class
}