Is there any other reason why NULL is not allowed in ArrayDeque besides "null is used as a special return value"?

Before you try to find duplicate question or downvotes, please let me explain :)

I think I read most of stackoverflow answers on this topic. They all summarize to this:

Null should not be inserted into a Queue, as null is also used as a special return value by some methods to indicate that the queue contains no elements.

They are totally right (let's ignore LinkedList here). If I were to call for example queue.poll() or queue.peek() and return type is null, I wouldn't know if that null represents null as element or null as no elements.

But any programmer with basic knowledge can do something like this to avoid given problem:

            //queue initialization..            
            if (!queue.isEmpty()){

So I must ask again. Was "null as special return type" only reason why it is 'banned' in mostly Queue implementations(except LinkedList)? Or I am missing something additional concerning this situation?

Read more here:

Content Attribution

This content was originally published by Stefan at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: