One of the Java 9 features I've tested is the List.of()
to create an unmodifiable list. I wonder - What is the purpose of this method if it returns an empty list of elements that can't be add / removed / edited?
The only thing that i was able to think of is to compare this list to another empty list, but then why not just to use someList.isEmpty()
?
As far as I know, the primary use of this method is for debugging. If you want to test your code on some list (say summing the elements), it is convenient to have a method that quickly creates a list. Because of the internal implementation the list is not mutable, but that's okay since we're just using it to test your code once.
UPDATE:
Since List.of(E e1, E e2, ...) are used for debugging, there is no reason not to include List.of() with no arguments, as often when debugging you will check for edge cases and see if your code also works for empty lists.