公共静态主变量的变体(字符串args []) [英] variations on public static main (String args[])

查看:87
本文介绍了公共静态主变量的变体(字符串args [])的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这4种方法签名之间有什么区别,为什么第4种签名不起作用?

What is the difference between these 4 method signatures, and why does the 4th not work?

public void main(String args[]) {... } 
public void main(String[] args) {... }
public void main(String... args) {... }
public void main(String[] args[]) {... }

推荐答案

前三个等效. * 最后一个等效于String[][] args(即数组数组),它不与Java对main的要求不符.

The first three are equivalent.* The last one is equivalent to String[][] args (i.e. an array of arrays), which doesn't match what Java requires for main.

但是,惯用的版本是第二个.

However, the idiomatic version is the second one.


*第三个仅从Java 5起有效.

这篇关于公共静态主变量的变体(字符串args [])的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆