Assign a new Reference for an Object
Please consider the following code:
Notice the line of code that I have made bold. There I was attempting to copy/clone the Stack [s] to a different variable [opWrongWay] ! However it isn't working.
//Finding shortest possible path.
int sizeOfStack = potentialPaths.get(0).size();
Stack<Node<Adjustment>> opWrongWay = new Stack<Node<Adjustment>>();
for(Stack<Node<Adjustment>> s : potentialPaths)
if(s.size() < sizeOfStack)
sizeOfStack = s.size();
[B]opWrongWay = s;[/B]
[opWrongWay] gives me an empty stack (where [s] has elements in).
So my question is, how do I hand over the stack [s] to a different variable (thus giving that variable the same stack content) whilst memory reference wise, keeping the two totally separate and thus in effect creating two objects. Is there an easy way to do this ?
I mean I know that I can iterate through [s] and copy the stuff to [opWrongWay] one by one, but surely there's an easier way ! no ?
I'd greatly appreciate any help.