【发布时间】:2012-06-05 12:48:34
【问题描述】:
我已经检查了实现,它是故意这样做的
public void put(E e) throws InterruptedException {
if (e == null) throw new NullPointerException();
这个惊喜对用户(例如,想要以这种方式表示流结束的信号)来说并不方便,并且打破了与集合的一般约定,集合很容易接受空元素。 BlockingQueue 区分空元素的意义何在?如果空值如此糟糕,我们是否应该完全避免使用它们并在 JLS 中强制执行这个低值?
【问题讨论】:
标签: java collections null nullpointerexception