我有2个独立的对象,分别创建,但是当我改变另一个时,一旦改变了。2“链接”对象
下面是创建对象代码:
private sMap unsolvedSudoku = new sMap();
private sMap solvedSudoku = new sMap();
private sMap userSudoku = new sMap();
algorithm alg = new algorithm(unsolvedSudoku);
这里是改变一个对象的代码:
//Generate a new sudoku
alg.generateFullList(); // - This changes unsolvedSudoku
solvedSudoku.setMatrix(unsolvedSudoku.getMatrix()); // - This basically copies an array of numbers from unsolvedSudoku to solvedSudoku.
new algorithm(solvedSudoku).printMap(); // This just prints out the array of numbers
alg.removeRandomNumbers(level); // This removes random numbers from unsolvedSudoku
new algorithm(solvedSudoku).printMap(); // this prints out the array again.
第一printMap和第二printMap是不同的,但他们不应该(至少据我所知)。这是为什么?此外,SMAP类没有任何静态变量或方法
非常相似,http://stackoverflow.com/questions/9403790/2d-arraylists-in-java/9403834#comment11883555_9403834 – 2012-02-24 21:31:47