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

后端 未结 4 1527
感动是毒
感动是毒 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:45

    Lets get to the source :

     public static final List EMPTY_LIST = new EmptyList<>();
    

    and

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

提交回复
热议问题