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回答

张勤一

2019-09-01

同学你好:

    repository 在 save 之前会做对 null 和空列表的判断,不会抛出异常。


    欢迎来 QQ 群随时交流、讨论,也非常感谢同学的支持!

1
1
JYChiu
非常感谢!
2019-09-01
共1条回复

Spring Cloud微服务架构 设计实现广告系统

广告营销系统,未来大中型企业的标配

2143 学习 · 928 问题

查看课程