I have a java class that looks like this:
public class Constants {
public class Commands {
public static final String CreateOrder = "CreateOrder";
}
}
I want to access "CreateOrder" constant, In java I can access it easily like this:
String co = Constants.Commands.CreateOrder
But in Scala this doesn't work why???
How can I access "CreateOrder" from Scala, I can't alter the Java code.
Thanks.
解决方案
As far as I know, there is no way to do what you want in Scala.
But if you absolutely cannot change the Java code then you could resort to some reflection trickery.
val value = classOf[Constants#Commands].getDeclaredField("CreateOrder").get(null)