String serviceName = "unknown";
// Read the name of the service to register as an argument
Object[] args = getArguments();
if (args != null && args.length > 0) {
serviceName = (String) args[0];
}这个if (args != null && args.length > 0)里的args != null 如果满足了,args.length > 0不也就满足了吗?是不是args.length > 0就不用写了?还是有些情况我没有考虑到?
谢谢大家指点!
// Read the name of the service to register as an argument
Object[] args = getArguments();
if (args != null && args.length > 0) {
serviceName = (String) args[0];
}这个if (args != null && args.length > 0)里的args != null 如果满足了,args.length > 0不也就满足了吗?是不是args.length > 0就不用写了?还是有些情况我没有考虑到?
谢谢大家指点!
或者
String[] args = {};此时虽然不等于null,但并没有参数,长度为0
可以看看《effective java》,看看函数的设计,我觉得如果是特定用途的函数 getArguments(),可以设计成返回不为空的数组和null,自然在调用的程序里可以不用写length>0了,api的说明一定要写清楚,调用api的人一看就明白