是否可以调用从另一个方法传递args []的main方法? [英] Is it possible to call the main method passing args[] from another method?
本文介绍了是否可以调用从另一个方法传递args []的main方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从另一个传递参数的方法调用类的main方法,例如从命令行运行类时。有办法吗?
I'm trying to call the main method of a class from another method passing arguments like when running the class from the command line. Is there a way to do this?
推荐答案
你可以拨打 main
调用任何其他(静态)方法的方法:
You can call the main
method as you would call any other (static) method:
MyClass.main(new String[] {"arg1", "arg2", "arg3"});
示例:
class MyClass {
public static void test() {
MyClass.main(new String[] {"arg1", "arg2", "arg3"});
}
public static void main(String args[]) {
for (String s : args)
System.out.println(s);
}
}
这篇关于是否可以调用从另一个方法传递args []的main方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文