我有一个检查空值的方法。有没有办法减少方法中的行数?目前,代码看起来很“脏”:
private int similarityCount (String one, String two) {
if (one == null && two == null) {
return 1;
} else if (one == null && two != null) {
return 2;
} else if (one != null && two == null) {
return 3;
} else {
if(isMatch(one, two))
return 4;
return 5;
}
}
最佳答案
private int similarityCount (String one, String two) {
if (one == null && two == null) {
return 1;
}
if (one == null) {
return 2;
}
if (two == null) {
return 3;
}
if (isMatch(one, two)) {
return 4;
}
return 5;
}
关于java - Java If Else 语句的简写形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41999782/