@deprecated("Low-level linked lists are deprecated due to idiosyncrasies in interface and incomplete features.", "2.11.0") trait LinkedListLike[A, This <: Seq[A] with LinkedListLike[A, This]] extends SeqLike[A, This] { self => var elem: A = _ var next: This = _ override def isEmpty = next eq this 第一个元素的尾部等于其头部,则为空,则你可以使用这个特性,人为制造空链表:val l1 = LinkedList(0,0,1,6,5,0,99,0,8) l1.next=l1虽然repl提示l1与l1.next都为LinkedList(),但是仍然可以访问其elem,l1.elem=0
深入一步分析:空链表link有link.next eq link 为true的性质,但是有这样性质的不一定为空链表,然而设计者却把这个必然不充分搞成充要了。
scala LinkedList 瑕疵
最新推荐文章于 2020-05-08 10:34:59 发布