We have:
Object head = listHead.datum;
listHead = listHead.next;
return head;
There are a number of references at play here:
listHead
is a referencehead
is a referencelistHead.datum
is a referencelistHead.next
is a reference
There are two actual object instances being referenced:
- whatever
datum
references (let's call that instanceD
) - whatever
next
references (let's call that instanceN
)
Here's how things go down.
listHead.datum
has a reference toD
listHead.next
has a reference toN
head
is given a reference toD
- listHead is given a reference to
N
(note thathead
is not changed) - you return
head
which still referencesD