Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Isn't the Java LinkedList API redundant?

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?

like image 782
ChrisOdney Avatar asked Apr 24 '13 09:04

ChrisOdney


1 Answers

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.

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

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

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

like image 174
Andreas Dolk Avatar answered Oct 20 '22 00:10

Andreas Dolk