我想从一个函数中取多个参数,并检查是否至少有一个参数不为空或空。最好/最有效的方法来检查是否至少有一个输入是由用户输入
现在我正在做这样的事情。
void foo(String a, String b, String c, String d, ... other strings){
//make sure at least one of the inputs are not null.
if(a!=null || b!=null || c!=null || d!=null ... more strings){
//do something with the string
}
}
这样的输入可以是foo(null, null, null, "hey");
,但它不能是foo(null, null, null, null);
什么我的问题是有没有更好的方式来做到这一点,而不是不断增加的if语句。林消隐了现在....感谢
多少个参数,你真的有这功能?这本身可能是一个问题。 – 2011-06-16 23:19:29