今天使用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();
    }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
  • 2022-12-23
猜你喜欢
  • 2021-09-27
  • 2021-10-01
  • 2022-12-23
  • 2021-04-24
  • 2022-12-23
  • 2022-01-07
  • 2021-12-08
相关资源
相似解决方案