java什么是子接口,java - 在子接口(interface)中声明具有相同声明的通用方法的体系结构重要性是什么...

接口List&Collection以及Set和Collection中声明了各种常用方法。

由于List和Set都扩展了Collection,因此在子接口中声明具有相同声明的通用方法的体系结构重要性是什么。public interface Collection extends Iterable {

int size();

boolean isEmpty();

boolean contains(Object o);

Iterator iterator();

Object[] toArray();

boolean add(E e);

boolean remove(Object o);//some more common method declaration

}

public interface List extends Collection {

int size();

boolean isEmpty();

boolean contains(Object o);

Iterator iterator();

Object[] toArray();

boolean add(E e);

boolean remove(Object o);

}

这并没有让我感到震惊,我只想知道这样做背后的概念。

最佳答案

这不是体系结构的原因。这是一种“覆盖”文档的方式。例如,对于List中的size方法,它们引用“列表”,而对于Colleciton中的size方法,它们引用“集合”。其他方法相同:

集合源和Javadoc/**

* Returns the number of elements in this collection. If this collection

* contains more than Integer.MAX_VALUE elements, returns

* Integer.MAX_VALUE.

*

* @return the number of elements in this collection

*/

int size();

/**

* Returns true if this collection contains no elements.

*

* @return true if this collection contains no elements

*/

boolean isEmpty();

列出源代码和Javadoc

/**

* Returns the number of elements in this list. If this list contains

* more than Integer.MAX_VALUE elements, returns

* Integer.MAX_VALUE.

*

* @return the number of elements in this list

*/

int size();

/**

* Returns true if this list contains no elements.

*

* @return true if this list contains no elements

*/

boolean isEmpty();

因此,这只是好的文档问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值