public CarList(CarList cl)
{
if(cl == null) throw new NullPointerException();
if (cl.head == null)
head = null;
else
{
// Notice that you cannot issue head = cl.head; otherwise both heads will point at the passed list;
head = null;
// Now create and copy all the nodes in the list
CarNode temp, temp2, temp3;
temp = cl.head;
temp2 = null;
temp3 = null;
while(temp != null)
{
if (temp2 == null) // The case for the first node
{
temp2 = new CarNode(temp.getCar(), null);
head = temp2;
}
else
{
temp3 = new CarNode(temp.getCar(), null);
temp2.setNext(temp3);
temp2 = temp3;
}
temp = temp.getNext();
}
// Avoid privacy leak; set all temporary pointers to null
temp = temp2 = temp3 = null;
}
}
我不太明白循环的作用......我无法解析代码。隐私权是否是由于临时变量持有地址这一事实?