Checking out Queue interface in Java here
I got confused by methods definitions :
element() Retrieves, but does not remove, the head of this queue.
is like
peek() Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
I can see that peek returns null if the queue is empty but both actually are defined as
Throws: NoSuchElementException - if this queue is empty
Same applies to remove() and peek();
Is there any goal behind this or it is just a design pitfall ?
remove()andpoll()element: "Retrieves, but does not remove, the head of this queue. This method differs from peek only in that it throws an exception if this queue is empty. "peekdoesn't throw an exception.