Collections.emptyList() returns a List<Object>?

前端 未结 4 745
轮回少年
轮回少年 2020-12-02 04:23

I\'m having some trouble navigating Java\'s rule for inferring generic type parameters. Consider the following class, which has an optional list parameter:

im         


        
4条回答
  •  遥遥无期
    2020-12-02 05:05

    You want to use:

    Collections.emptyList();
    

    If you look at the source for what emptyList does you see that it actually just does a

    return (List)EMPTY_LIST;
    

提交回复
热议问题