Java LinkedList API 不是多余的吗? [英] Isn't the Java LinkedList API redundant?

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

问题描述

Java LinkedList 类中的方法 addaddLastofferofferLast 是否执行一样?如果是这样,为什么 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 类实现了接口 ListDeque.所以这个类需要实现这四个方法,即使你是对的,它们的作用完全相同.

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<>();

例如,您将看不到 addLastofferofferLast 方法.

for example, then you won't see the methods addLast, offer and offerLast.

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

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