Para evitar NullPointerException no deseado.
En su código, puede devolver un ArrayList "vacío" normal en lugar de devolver nulo. Pero, de esa manera, seguirás creando objetos NUEVOS (con una capacidad predeterminada de 10) en cada ejecución que no es un enfoque de memoria eficiente. En lugar de eso, si devuelve emptyList, se devolverá la misma instancia en cada invocación. De esta forma, te ahorra la NullPointerException no deseada de una manera más eficiente.Aquí está el recorte del Javadoc para emptyList:
/**
* Returns the empty list (immutable). This list is serializable.
*
* <p>This example illustrates the type-safe way to obtain an empty list:
* <pre>
* List<String> s = Collections.emptyList();
* </pre>
* Implementation note: Implementations of this method need not
* create a separate <tt>List</tt> object for each call. Using this
* method is likely to have comparable cost to using the like-named
* field. (Unlike this method, the field does not provide type safety.)
*
* @see #EMPTY_LIST
* @since 1.5
*/
respondió Posiblemente [aquí] (http://stackoverflow.com/questions/5552258/collections-emptylist-vs-new-instance) –
inmutabilidad es bueno para usted ! –