今天使用Collections.emptyList(),返回一個空的List
但是發現它不支持Add功能,調用Add會拋出unsupportedException,
在以后要返回一個空的List,并還需要后續操作時,不能使用Collections.emptyList()方法,看文檔發現,List的實現類都有自己的實現,而返回的EmptyList的實現沒有實現add(int index, E element方法,使用了
AbstractList.add(int index, E element){
throw new UnsupportedOperationException();
}