等价方法超载为什么有必要?

 气质朱总_206 发布于 2023-01-29 14:23

我浏览了Google制作的一些JAVA代码,我找到了ImmutableSet:http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableSet.html

他们用其他几种方法实现了of()方法:

public static  ImmutableSet 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 static  ImmutableSet create(E... elements)

包裹了

private static  ImmutableSet create(Iterable iterable, int count);

方法.public方法只是将参数传递给create(E ... elements)signatured方法,该方法最终调用另一个create方法.

我想由于我们有(E ... elements)方法,因此不需要公开具有固定计数参数的方法.

我的问题是他们为什么这样做呢?性能?或者这是一种模式?

谢谢.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有