Collections.EMPTY_MAP,EMPTY_LIST,EMPTY_SET的用途是什么

use*_*855 5 java

既然所有这些都是不可变的,为什么会想要呢?

mre*_*mre 8

有时它是回归的更好选择null.

public List<?> getList(){
    if(list == null){
        return Collections.emptyList();
    }

    return list;
}
Run Code Online (Sandbox Code Playgroud)

参考