RFR: 8258852: Arrays.asList() for single item could be replaced with Collections.singletonList()

Сергей Цыпанов github.com+10835776+stsypanov at openjdk.java.net
Mon Dec 28 21:28:56 UTC 2020


On Thu, 24 Dec 2020 17:30:41 GMT, Xue-Lei Andrew Fan <xuelei at openjdk.org> wrote:

> > What about using List.of() instead?
> 
> For now, the Collections.singletonList() is more compact, which uses one class variable. While List.of(T) shares the internal implementation with List.of(T t1, T t2), which uses two class variables.

There's one more issue about it: `List.of()` throws NPE when argument is `null` while `Collections.singletonList()` returns a list with `null` inside.

-------------

PR: https://git.openjdk.java.net/jdk/pull/1872



More information about the security-dev mailing list