[英]What does `public static <T> void main(String[] args)` stand for?
What does public static <X> void main(String[] args)
stand for? public static <X> void main(String[] args)
代表什么? I tried to understand but didn't get. 我试图理解,但没有得到。 I know about
public static void main(String[] arg)
. 我知道
public static void main(String[] arg)
。 Thanks in advance. 提前致谢。
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 public
- 它是一个公共方法,可以访问任何可以访问声明它的类的东西 <X>
- this is (somewhat bizarrely) a generic method with an unbound type variable X
<X>
- 这是(有点奇怪)具有未绑定类型变量X
的通用方法 static
- the method is related to the type in which it's declared, not any specific instance of the type static
- 该方法与声明它的类型有关,而不是该类型的任何特定实例 void
- the method doesn't return a value void
- 该方法不返回值 main
- the name of the method main
- 方法的名称 String[] args
- a single parameter, of type String[]
and called args
String[] args
- 一个String[]
类型的参数,名为args
main
is the entry point used by the JVM. main
是JVM使用的入口点。 When you run: 当你运行:
java foo.bar.Baz
it will try to find a main
method in class foo.bar.Baz
. 它会尝试在类
foo.bar.Baz
找到一个main
方法。 I've never seen a generic main
method before, admittedly. 不可否认,我以前从未见过一种通用的
main
方法。 For more about generics in Java, read the Java Generics FAQ . 有关Java中泛型的更多信息,请阅读Java Generics FAQ 。
<X>
is known as Type Parameter . <X>
称为类型参数 。
This is applicable to the methods, classes, variables, etc.. But its most important use is to make the Collections more type safe. 这适用于方法,类,变量等。但最重要的用途是使集合更安全。
<X>
will mark a certain Type within the main()
method. <X>
将在main()
方法中标记某个Type 。
The whole sentence dissection is as follows: 整个句子解剖如下:
public
- is the access-modifier, means that this method is accessible from anywhere. public
- 是access-modifier,意味着可以从任何地方访问此方法。 <X>
- Type Parameter, as mentioned above <X>
- 类型参数,如上所述 void
- This method will not return anything void
- 此方法不会返回任何内容 main
- Method's name, main() method is the entry point of any pgm in java. main
- 方法的名称,main()方法是java中任何pgm的入口点。 String[]
: Array Of String. String[]
:String数组。 args
: Array reference variabl of type String. args
:String类型的数组引用变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.