I suspect your two options may be:
- create an accessor method within your Scala class
- create an accessor method within your Java class using reflection to find that field and read it
e.g.
class A {
val class = 1
def clazz = class
}
Вопрос
I'm working on a project in Java/Scala that analyse Java code. In my scala code I have :
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
}
}
And I need to access it from Java
class MyJavaClass{
void m(){
/* ... */
int value = p.NodeKind.//how can I access to `class` or interface ?
/* ... */
}
}
For now I have settled with Brian Agnew solution, I added a field
val classKind = `class`
in my scala object and I can access it with p.nodeKind.classKind()
in my java code but I would really prefer to know the compilation (mangling?) rules for `class` and interface to access it directly.
Решение
I suspect your two options may be:
e.g.
class A {
val class = 1
def clazz = class
}