I have a Java code that looks for annotations in static methods of a class.
processor.readStatics( MyClass.class ); // Takes Class<?>
How can I provide the methods of a scala companion object to this function from within scala?
class MyClass {
}
object MyClass {
def hello() { println("Hello (object)") }
}
I seems that:
MyClass$.MODULE$.getClass()
should be the answer. However, MyClass$ seems to be missing from scala (in 2.10, at least) and only visible to Java.
println( Class.forName("MyClass$.MODULE$") )
also fails.
Class.forName("MyClass$MODULE$")
? For inner classes no need for additional.
. – Gábor BakosClass.forName("MyClass$$MODULE$")
, because we have to use$
instead of.
for inner classes. – Gábor BakosClass.forName(MyClass$)
. At least it is found with Scala 2.10.3. – Gábor Bakos