Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java, two objects, object1 = object2 = class/type ... don't understand

I have two instance variables, head and tail. In the code there's a line:

head = tail = new Node<E>();

Does this mean that there are two instances, head and tail, of class Node? I'm quite confused here.

like image 217
Jonny Stewart Avatar asked Nov 27 '22 21:11

Jonny Stewart


1 Answers

It simply means:

tail = new Node<E>();
head = tail;

So there are 2 references (head and tail) pointing to the same Node<E> instance.

like image 66
Juvanis Avatar answered Jan 26 '23 00:01

Juvanis