我編碼在Java中的一個項目,並創建了一個類用下面的代碼:如何創建現有類的新實例?
public class VehInfo {
private int[][] traffic = new int[20][150];
private int mintime = 0;
private int numvehicles = 1;
private int[] vehiclecode = new int[5];
public VehInfo(int[][] traffic, int mintime, int numvehicles, int[] vehiclecode) {
this.traffic = traffic;
this.mintime = mintime;
this.numvehicles = numvehicles;
this.vehiclecode = vehiclecode;
}
}
我想用下面的代碼
VehInfo vehinfo = new VehInfo(new int[20][150], new int, new int, new int[5]);
創建這個類的一個新實例。然而, Netbeans的通知我:
必需的:(INT [] [],INT,INT,INT [])
發現:(int [] [],int [],int [],int [])
我在想什麼?我顯然不會將這些變量初始化爲int [],那麼爲什麼它們會被拾取?
你認爲那是新的INT'將完成? – Gimby
新的int應該被int替換掉 – user1121883
通過哪個int? 「new int」的價值是什麼? – Kayaman