有人能够为什么代码不起作用提供一些见解吗?问题在于countries部分的[numCountries]=newCountry;
我不确定为什么会一直提示类型不匹配,无法将Country[]转换为Country,但我认为我的countries[numCountries]是Country[]类型,因为我已经在代码的第二行调用了它,并给它赋予了那种类型?
public class World{
private Country[] countries;
private int numCountries=0;
public boolean addCountry(Country[] newCountry){
if(!(newCountry==null)){
countries[numCountries]=newCountry; //the newcountry part doesnt work, red zigzag line underlining it here im not sure why
numCountries++;
return true;
}
else
return false;
}
}
if(newCountry!=null)
更整洁。 - Tass