我浏览了Google制作的一些JAVA代码,我找到了ImmutableSet:http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableSet.html
他们用其他几种方法实现了of()方法:
public staticImmutableSet of(E e1, E e2); public static ImmutableSet of(E e1, E e2, E e3); public static ImmutableSet of(E e1, E e2, E e3, E e4); public static ImmutableSet of(E e1, E e2, E e3, E e4, E e5); public static ImmutableSet of(E... elements);
我查看了此处的实施:https://code.google.com/p/google-collections/source/browse/trunk/src/com/google/common/collect/ImmutableSet.java
有一个创建方法,具有以下签名:
private staticImmutableSet create(E... elements)
包裹了
private staticImmutableSet create(Iterable extends E> iterable, int count);
方法.public方法只是将参数传递给create(E ... elements)signatured方法,该方法最终调用另一个create方法.
我想由于我们有(E ... elements)方法,因此不需要公开具有固定计数参数的方法.
我的问题是他们为什么这样做呢?性能?或者这是一种模式?
谢谢.