【发布时间】:2012-04-28 08:13:44
【问题描述】:
我的印象是 main 方法必须具有“public static void main (String[] args){}”的形式,你不能传递 int[] 参数。
但是,在 Windows 命令行中,当运行以下 .class 文件时,它接受 int 和 string 作为参数。
例如,使用此命令将给出输出“stringers”:“java IntArgsTest stringers”
我的问题是,为什么?为什么这段代码会接受一个字符串作为参数而不会出错?
这是我的代码。
public class IntArgsTest
{
public static void main (int[] args)
{
IntArgsTest iat = new IntArgsTest(args);
}
public IntArgsTest(int[] n){ System.out.println(n[0]);};
}
【问题讨论】:
-
根据其他人的反应,它对我来说失败了。您没有说明您正在使用哪个 JRE 或操作系统并没有帮助,但我强烈怀疑您没有运行您认为正在运行的程序。
标签: java command-line cmd arguments main