加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 为什么我们可以将空值添加到LinkedList DESPITE强烈劝

发布时间:2020-12-15 01:06:04 所属栏目:Java 来源:网络整理
导读:来自Deque的Javadoc: While Deque implementations are not strictly required to prohibit the insertion of null elements,they are strongly encouraged to do so. Users of any Deque implementations that do allow null elements are strongly encour

来自Deque的Javadoc:

While Deque implementations are not strictly required to prohibit the insertion of null elements,they are strongly encouraged to do so. Users of any Deque implementations that do allow null elements are strongly encouraged not to take advantage of the ability to insert nulls. This is so because null is used as a special return value by various methods to indicated that the deque is empty.

我在现有问题中找不到答案:Why can we add null elements to a java LinkedList?

最佳答案
允许这样的规定使程序员的生活更轻松.我可以想一个例子.

假设有一个链接列表的房屋和一个postMan来按顺序向每个房子发送信件.
linkedList中的每个节点都存在.房屋有家庭对象作为其价值.
在某些情况下,家庭可能不在那里,那么家庭对象将具有空值.

但对于邮递员来说,这是不相关的,因为他仍然必须访问该节点.
PostOffice建议所有家庭如果他们要离开房子就指示邮局,以便postMan不需要访问那所房子(如果可能的话).

但出于某种目的,房主决定不通知postOffice这种情况,并希望继续收到信件(间接邮寄访问).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读