java的List接口中为什么要包含所有Collection接口中的方法?

最近在学习Java集合框架源码,在看到List接口时发现虽然List接口继承自Collection接口,但是Collection接口中一些已定义的抽象方法(例如:size(),isEmpty()等)在List接口中却又重新定义了一次,为什么这么做呢?答案在List接口描述中已经给了,我们可以在List接口描述中看到如下描述:

The List interface places additional stipulations, beyond those specified in the
 Collection interface, on the contracts of the iterator, add, remove, equals, and 
hashCode methods.  Declarations for other inherited methods are also included here for 
convenience.

翻译:
List接口在Collection接口指定的约束之外,在iterator、add、remove、equals和hashCode方法上添加了其他的约定。为了方便起见,还包含了其他继承方法的声明

我们可以看到,之所以在List接口中重新定义一次,主要是为了方便(for convenience),不然总要往上一层层去父类中找,就会很繁琐。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值