Java LinkedList API 不是多余的吗? [英] Isn't the Java LinkedList API redundant?
问题描述
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
方法.
for example, then you won't see the methods addLast
, offer
and offerLast
.
这篇关于Java LinkedList API 不是多余的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!