简体   繁体   English

什么是`public static <T> void main(String [] args)`代表什么?

[英]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

  1. <X> is known as Type Parameter . <X>称为类型参数

  2. This is applicable to the methods, classes, variables, etc.. But its most important use is to make the Collections more type safe. 这适用于方法,类,变量等。但最重要的用途是使集合更安全。

  3. <X> will mark a certain Type within the main() method. <X>将在main()方法中标记某个Type

  4. 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.

相关问题 “public static void main(String args[])”的Eclipse快捷方式是什么? - What is the Eclipse shortcut for “public static void main(String args[])”? `public static void main args` 是什么意思? - What does `public static void main args` mean? 了解公共静态void main(String [] args) - Understanding public static void main(String[] args) 对main方法的误解/“ public static void main(String [] args)”的观点 - Misunderstanding main method/the point of “public static void main(String[] args)” public static void main(String args[]) 为什么 string args[] 是强制性的,为什么我们不使用 public static void main(Object args[])? - public static void main(String args[]) why string args[] is compulsory ,why we not use public static void main(Object args[])? 需要添加“ public static void main(String [] args)”, - Need to add a “public static void main(String[] args)”, 使用 int 而不是 String:public static void main (int[] args) - Using int Instead Of String: public static void main (int[] args) 代码签名和编写步骤 public static void main(String args[] ) - Code signature and steps to write public static void main(String args[] ) public static void main(String[] args) 抛出异常 - public static void main(String[] args) throws Exception 我应该把 public static void main(String[] args) 放在哪里? - Where do I put public static void main(String[] args)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM