使用Collections.emptyList()生成的List不支持add方法

今天使用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();
    }
posted @ 2011-07-12 18:40  跳刀的兔子  阅读(5651)  评论(0编辑  收藏  举报