Collections.emptyList() 的疑问
来源:5-17 推广单元限制服务功能实现(2)

JYChiu
2019-09-01
Collections.emptyList()
继承 AbstractList
后没有实现 add()
、remove()
等方法,源码中这么配置:
public void add(int index, E element) {
throw new UnsupportedOperationException();
}
public E remove(int index) {
throw new UnsupportedOperationException();
}
所以,AdUnitServiceImpl
中:
List<Long> ids = Collections.emptyList();
ids = keywordRepository.saveAll (...)
这行代码不会报错 UnsupportedOperationException
吗?
写回答
1回答
-
同学你好:
repository 在 save 之前会做对 null 和空列表的判断,不会抛出异常。
欢迎来 QQ 群随时交流、讨论,也非常感谢同学的支持!
112019-09-01
相似问题