注意:返回0长度的数组大概聚集,而不是 null
而且当我们每次都 new ArrayList() 大概 new LinkedList() ,在创建的时候就会有初始巨细,多少会占用一些内存。每次使用都 new 一个空的 list 聚集,浪费就聚沙成塔,浪费就严重啦。
/*** The empty map (immutable). This map is serializable.** @see #emptyMap()* @since 1.3*/@SuppressWarnings("rawtypes")public static final Map EMPTY_MAP = new EmptyMap();/*** Returns an empty map (immutable). This map is serializable.**
This example illustrates the type-safe way to obtain an empty map:* @implNote Implementations of this method need not create a separate* {@code Map} object for each call. Using this method is likely to have* comparable cost to using the like-named field. (Unlike this method, the* field does not provide type safety.)** @param the class of the map keys* @param the class of the map values* @return an empty map* @see #EMPTY_MAP* @since 1.5*/@SuppressWarnings("unchecked")public static final Map emptyMap() {return (Map) EMPTY_MAP;}
——乐于分享,共同进步,欢迎补充
——Treat Warnings As Errors
——Any comments greatly appreciated
——Talking is cheap, show me the code
——恳切欢迎各位交换讨论!QQ:1138517609
——CSDN:https://blog.csdn.net/u011489043
——简书:https://www.jianshu.com/u/4968682d58d1
——GitHub:https://github.com/selfconzrr