Question

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.

Was it helpful?

Solution

I suspect your two options may be:

  1. create an accessor method within your Scala class
  2. 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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top