What does public static <X> void main(String[] args) stand for? I tried to understand but didn’t get. I know about public static void main(String[] arg).
Thanks in advance.
What does public static <X> void main(String[] args) stand for? I tried to understand
Share
Let’s look at each bit in turn:
public– it’s a public method, accessible to anything which has access to the class in which this is declared<X>– this is (somewhat bizarrely) a generic method with an unbound type variableXstatic– the method is related to the type in which it’s declared, not any specific instance of the typevoid– the method doesn’t return a valuemain– the name of the methodString[] args– a single parameter, of typeString[]and calledargsmainis the entry point used by the JVM. When you run:it will try to find a
mainmethod in classfoo.bar.Baz. I’ve never seen a genericmainmethod before, admittedly. For more about generics in Java, read the Java Generics FAQ.