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

后端 未结 4 1529
感动是毒
感动是毒 2020-12-01 04:18

In Java, we have Collections.emptyList() and Collections.EMPTY_LIST. Both have the same property:

Returns the empty list (immutable). This list is ser

4条回答
  •  感情败类
    2020-12-01 04:32

    In other words, EMPTY_LIST is not type safe:

      List list = Collections.EMPTY_LIST;
      Set set = Collections.EMPTY_SET;
      Map map = Collections.EMPTY_MAP;
    

    As compared to:

        List s = Collections.emptyList();
        Set l = Collections.emptySet();
        Map d = Collections.emptyMap();
    

提交回复
热议问题