What is the difference between Collections.emptyList() and Collections.EMPTY_LIST

  • Collections.EMPTY_LIST returns an old-style List
  • Collections.emptyList() uses type-inference and therefore returns
    List<T>

Collections.emptyList() was added in Java 1.5 and it is probably always preferable. This way, you don’t need to unnecessarily cast around within your code.

Collections.emptyList() intrinsically does the cast for you.

@SuppressWarnings("unchecked")
public static final <T> List<T> emptyList() {
    return (List<T>) EMPTY_LIST;
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)