Collections.emptyList () vs guava ImmutableList.of ()

The title says it all. This is actually a simple question. I just wanted to understand how both of these things really work. What would be the best option to return an immutable empty list? Would it be better to do Collections.emptyList () or ImmutableList.of () or is there a third and best option?

+4
source share
1 answer

I would use Collections.emptyList()because

1) why use a third-party library when you already have the same in the JDK

2) Collections.emptyList()returns a real simple private class Collections.EMPTY_LIST(see Collections.java in the JDK).

ImmutableList.of() Guava , , new Object[0].

, ImmutableList.

+4

Source: https://habr.com/ru/post/1674357/


All Articles