Java SE5引入了可变参数列表特性,使用的时候需要注意一些细节
void test(String... args) {
if(args == null) {
System.out.println("args is null");
} else {
System.out.println("args not null, lenght is " + args.length);
}
}
method | args == null | args.length |
test() | false | 0 |
test("gui") | false | 1 |
test(null) | true | |
test(null, null) | false | 2 |
test(new String[]{null}) | false | 1 |