我创建了一个矩阵对象(如数学矩阵,例如一个4x4数字块),它工作正常,可以设置行,列,变量就好了,但是,我不能有多个相同的对象,我创建了一个Matrix对象的ArrayList,每个对象都有三个变量,但是当我调用changeVar(Matrix x,int variable)并刷新矩阵的打印输出时,它会更改所有对象的数字,我改变了变量。所以看起来它只是一遍又一遍地创建相同的实例,如果你改变它,它会改变它们,我是否错过了任何明显的东西?创建一个对象[多个相同的实例]
public class Matrices {
private static int row, col, value, newRow, newCol;
public Matrices(int row, int col, int value) {
this.value = value;
this.row = row;
this.col = col;
}
public static void setRow(int row) {
Matrices.row = row;
}
public static void setValue(int value) {
Matrices.value = value;
}
public static void setCol(int col) {
Matrices.col = col;
}
public static int getCol(Matrices x) {
return col;
}
public static int getRow(Matrices x) {
return row;
}
public static int getValue(Matrices x) {
return value;
}
public static Matrices changeValue(Matrices x, int value) {
newRow = getRow(x);
newCol = getCol(x);
return new Matrices(newRow, newCol, value);
}
}
ooh,很好,谢谢,我觉得这是因为它的工作,然后我修复了警告并继续前进,然后突然它不起作用..现在,它在对接中变得很痛苦,我不能得到它。谢谢! – Samuel 2010-10-19 23:32:23