When I execute the below code it works without any problem.
List<String> singletonList = Collections.singletonList("Hello");
List<String> s = Collections.emptyList();
singletonList.addAll(s);
However, when I try to do following it gives me compile error. Why?
List<String> singletonList = Collections.singletonList("Hello");
singletonList.addAll(List<String> Collections.emptyList());
Collections.emptyList is a type-safe way of creating an empty list. But why doesn't my program compile then? I know I cannot add to immutable list (UnsupportedOperationException) but adding an empty list is allowed. Actually I was testing this and I noticed above thing.