The following code gives a compile error:
public void method(List<String> aList) {}
public void passEmptyList() {
method(Collections.emptyList());
}
Is there a way to pass an empty list to method without
- Using an intermediate variable
- Casting
- Creating another list object such as
new ArrayList<String>()
?
Replace
with
The
<String>after the.is an explicit binding foremptyList‘s type parameter, so it will return aList<String>instead of aList<Object>.