标签:amp point 比较 array ble int poi ... iter
1.把字符串常量放在前面
通过把字符串常量房子啊比较函数equals()比较项的左边来防止偶然的NullPointerException:
//Bad
if(variable.equals("literal")) {...}
//Good
if("literal".equals(variable)) {...}
2.检查null和长度
不管什么时候你有一个集合、数组或者其他的,确保它存在并且不为空:
//Bad
if(array.length > 0) {...}
//Good
if(array != null && array.length > 0) {...}
标签:amp point 比较 array ble int poi ... iter
原文地址:http://www.cnblogs.com/lmmblogs/p/6923279.html