Java LinkedList API是否冗余? [英] Isn't the Java LinkedList API redundant?

查看:49
本文介绍了Java LinkedList API是否冗余?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java LinkedList类中的方法 add addLast offer offerLast 不执行一样?如果是这样,为什么API设计会为了简洁而牺牲简洁性?

Don't the methods add, addLast, offer and offerLast in the Java LinkedList class perform the same thing? If so, why does the API design trade off brevity for redundancy?

推荐答案

LinkedList 类实现接口 List Deque .因此,尽管您是对的,但类仍需要实现这四个方法,它们的作用完全相同.

The LinkedList class implements the interfaces List and Deque. So the class needs to implement those four methods even though, you're right, they do quite the same.

顺便说一句, LinkedList 不是API.如果您使用界面,例如

By the way, the LinkedList is not the API. If you use an interface, like

List<String> list = new LinkedList<>();

例如,

,那么您将不会看到方法 addLast offer offerLast .

这篇关于Java LinkedList API是否冗余?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆