我有下面的代码创建一个对象数组,然后尝试添加一个相同类型的对象。
我收到错误“语法错误,插入”新的ClassType()“以完成表达式” 在线
vehicles.[index] = nextVehicle;
但在我看来,它没有任何问题。从长到int的演员是否会引起一些问题?
long vehicleSize = getVehicleSize();
Vehicle[] vehicles= new Vehicle[(int)vehicleSize];
Vehicle nextVehicle = null;
int offSet = 0;
int index= 0;
while (offSet < vehicleSize) {
nextVeh = new Vehicle(db, offSet);
vehicles.[index] = nextVehicle;
index++;
offSet += nextVehicle.getSize();
}
答案 0 :(得分:7)
vehicles.[index] = nextVehicle;
应该是
vehicles[index] = nextVehicle;
和
nextVeh = new Vehicle(db, offSet);
应该是
nextVehicle = new Vehicle(db, offSet);