spring-boot
spring-boot copied to clipboard
Use List.copyOf() instead of Collections.unmodifiableList()
We can safely use List.copyOf() because we check if (providers) is null.
If use List.copyOf()
- Clean code
- Performance optimization
- Guarantees a truly immutable list.
I think this is probably safe, but we need to be a little careful using List.copyOf. Unlike Collections.unmodifiableList(new ArrayList<>(...)) it will throw an exception if any of the elements are null.
Thanks @bazzi2548!