Equivalient method overload why necessary?

前端 未结 3 1169
甜味超标
甜味超标 2021-01-18 00:32

I browsed some JAVA code made by Google, and I found the ImmutableSet: http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableSet.html

3条回答
  •  遇见更好的自我
    2021-01-18 00:39

    They do it to manage memory in a more efficient way. If you have an immutable collection with a small set of items, it is better to explicitly fix the size of the collection. Otherwise, Java will create a collection of a size that is bigger. E.g: A HashSet, unless specified otherwise will have an intial size of 12 entries.

提交回复
热议问题