我已經開始寫一個類來矩陣模型和編譯器給了我這個消息時「找不到符號」:測試Java代碼
Matrix.java:4: cannot find symbol symbol : constructor Matrix(int[][]) location: class Matrix Matrix y = new Matrix(x);
這是我試圖編譯代碼:
public class Matrix<E> {
public static void main(String[] args) {
int[][] x = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3}, {1, 2, 3}};
Matrix y = new Matrix(x);
System.out.println(y.getRows());
System.out.println(y.getColumns());
}
private E[][] matrix;
public Matrix(E[][] matrix) {this.matrix = matrix;}
public E[][] getMatrix() {return matrix;}
public int getRows(){return matrix.length;}
public int getColumns(){return matrix[0].length;}
}
所以,我的問題是,爲什麼我得到這個錯誤,我應該改變什麼來解決這個問題?
謝謝,編譯和運行在我的機器上。猜猜在我開始使用它之前,我應該多讀一些關於泛型的語法 – 2010-07-24 22:44:09
爲什麼不接受答案? – duffymo 2010-07-24 22:46:03
對於接受答案的速度,SO有時間限制。我嘗試了一下,但我必須等待一段時間才能接受(除非有人提出了一個超級驚人的答案,證明了神粒子的存在或類似的東西) – 2010-07-24 22:50:26