Java main 参数 args

来源:互联网 发布:saas 系统架构源码 编辑:程序博客网 时间:2024/05/29 06:44

Java: Check if command line arguments are null, http://stackoverflow.com/questions/3868878/java-check-if-command-line-arguments-are-null

Command-Line Arguments, Command-Line Argumentshttp://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html

检查 args 是否为 null

You should check for (args == null || args.length == 0). Although the null check isn't really needed, it is a good practice.


一段有趣的代码:

public class Test{public static void main(String[] args) throws InterruptedException{String [] dummy= new String [] {};if(dummy == null){System.out.println("Proper Usage is: java program filename");System.exit(0);}}}

上面这个例子跟String[] args 道理一样

String[] dummy = new String[] {"123","abc"};


public class Test{public static void main(String[] args) throws InterruptedException{String [] dummy= new String [] {};if(dummy.length == 0){System.out.println("haha.");}}}