Type-safe, generic, empty Collections with static generics
- by Droo
I return empty collections vs. null whenever possible. I switch between two methods for doing so using java.util.Collections:
return Collections.EMPTY_LIST;
return Collections.emptyList();
where emptyList() is supposed to be type-safe. But I recently discovered:
return Collections.<ComplexObject> emptyList();
return…