Reputation: 27425
I'm reading B. Goetz Java Concurrency In Practice and now I'm at the section about Concurrent Collections. He describes the Queue
interface added in Java 5.0 as follows:
While you can simulate the behavior of a
Queue
with aList
— in fact,LinkedList
also implementsQueue
—theQueue
classes were added because eliminating the random-access requirements of List admits more efficient concurrent implementations.
It seems a bit confused. I looked at the LinkedList
interface and noticed that it doesn't implement RandomAccess
, but ArrayList
does. That's quite obvious as that LinkedList
provides linear time random access to its elements.
Couldn't you explain what he meant?
Upvotes: 2
Views: 50
Reputation: 73568
He's not referring to the RandomAccess
marker interface, but the random access methods such as get(index)
. When implementing a Queue
you don't need to worry about implementing those methods, as they could be extremely inefficient and possibly prevent you from making the class as performant as you'd like.
Upvotes: 4