I’ve two classes:
public class UThreadApp {
public static void main(String[] args) {
newUThread("umain", args);
...
}
native void newUThread(String method, String[] args);
}
public class App extends UThreadApp {
public static void umain(String[] args) {
...
}
}
Application is executed as java App.
App inherits main from UThreadApp such that main calls App.umain. I’ve to get programmatically the main class name App from Java or JNI so as to call App.umain from JNI code. Do you see a way to do that?
Idioms such that new Object(){}.getClass().getEnclosingClass() don’t work since they return UThreadApp.
Static methods have no class, and no
thisreference. YourAppclass will “inherit” main insofar as that main is usually callable asApp.mainas well. But you cannot override static methods in the common sense. Once the method got invoked, there is no way to determine what name was used to invoke it. So nothing you do, on the java side or in native code, will give you the information you desire. Apart from hacking the java executable and figuring out its command line arguments or similar brutal and unsupported approaches, that is.Note: You also have an error where the static
maintries to call the non-staticnewUThread.What you could do is something like this, to leave the
staticscope and get a reasonablethispointer: