element
is a reference
to a MovieNode
, element.previous.next
is another reference to the same MovieNode
. The difference between these two is that element
is a temporary reference within the scope of your function ; however the element.previous.next
is a reference held by the element.previous
node which is defined outside this scope.
It is important to remember that in Java saying a = b
where a
and b
are objects, means that a
and b
refer to the same object. If you modify a
, b
will also change.
This is why you copied the MovieNode
at the beginning of the function : to effectively copy the node instead of referring to it. The rest of the affectations just manipulate the previous
and next
references and do not handle the actual objects.