如何对这段代码进行优化看起来更加简介高效 if oldValue != null && newValue != null if !oldValueequalsnewValue MapStringString difMap=new HashMap; difMapputfB
可以使用三目运算符来简化代码:
if (oldValue != null && newValue != null && !oldValue.equals(newValue)
|| oldValue == null && newValue != null
|| oldValue != null && newValue == null) {
Map<String,String> difMap=new HashMap<>();
difMap.put("fBgzd",colum);
difMap.put("fBgq",String.valueOf(oldValue));
difMap.put("fBgh",String.valueOf(newValue));
diffColums.add(difMap);
}
这样可以将三个if语句合并为一个,代码更加简洁。
原文地址: https://www.cveoy.top/t/topic/ff7a 著作权归作者所有。请勿转载和采集!