說明:為了避免在數組和集合的獲取上增加null的判斷,同時也能減少不必要的空指針異常,通常會在業務返回零數組或空集合。
方法:
1、數組:
定義全局靜態常量來減少內存開銷:private static final int EMPTY_ARRAY = new int[0];,當然,也可以直接局部變量等等。
2、集合:
使用工具類Collections的emptyList()進行放回。
參考:
http://blog.csdn.net/tounaobun/article/details/8502160
https://www.codeproject.com/Articles/794448/Is-it-Really-Better-to-Return-an-Empty-List-Instea
