public static void main(String[] args) {
String result = replaceStr("jaja");
if (result != null) { //在这里又要判断下非空
int count = 50 + Integer.parseInt(result);
}
}
public static String replaceStr(String tem){
String result;
if (tem == null) {
result = null;
} else {
String substring = tem.substring(0, 1);
result = substring;
}
return result;
}
如上代码,我的疑惑时,当参数tem为空,方法返回null,那岂不是又要在调用replaceStr这个方法的地方又要判断次返回值是否为null?那这个代码看上去不是很难看,好多if(**!=null)这样的语句。
我想问的是:有没有一种设计,可以只要在一处判断非空,其他地方只要写业务逻辑就行了?
谢谢
白猪掌柜的
一只甜甜圈
芜湖不芜
HUX布斯
慕尼黑5688855
大话西游666
相关分类