java - Modifying one object is changing value in a second object -


state st = sc.que.remove();  system.out.println(st.getmoves() +" - goal: " + arrays.tostring(st.getgoal()) + "- puzzle: " + arrays.tostring(st.getpuzzle()));  state ss = new state(st.getpuzzle(), st.getspace(), st.getmoves(), st.getgoal()); ss.moveup();  system.out.println(st.getmoves() +" - goal: " + arrays.tostring(st.getgoal()) + "- puzzle: " + arrays.tostring(st.getpuzzle())); 

basically have 1 state, print off it's value. create second state using value of first create exact copy. modify second state using method moveup() swaps couple elements in array withine state. reprint value first state 1 not changed different.

what members of state? if objects, don't copy them using getmember() passing reference them second constructor. if call method changes member of first object, identical member changed in second object, too.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -