$0 (Program Name) in Java? Discover main class?

前端 未结 8 949
死守一世寂寞
死守一世寂寞 2020-12-03 00:23

Is there a way to find the name of the program that is running in Java? The class of the main method would be good enough.

8条回答
  •  渐次进展
    2020-12-03 01:08

    Try this :

    Java classes have static instance of their own class (java.lang.Class type).

    That means if we have a class named Main. Then we can get its class instance by Main.class

    If you're interested in name only then,

    String className = Main.class.getName();

提交回复
热议问题