我有一個名爲「表」擴展ArrayList的類。在這個類中,我有一個名爲toArray()的方法。每當我編譯我得到的錯誤:「表中的toArray()不能實現java.util.List中的toArray()返回類型void與java.lang.Object不兼容[toArray方法不工作擴展ArrayList <>
這裏是Table類:
public class Table extends ArrayList<Row>
{
public ArrayList<String> applicants;
public String appArray[];
public String appArray2[] = {"hello", "world","hello","world","test"};
/**
* Constructor for objects of class Table
*/
public Table()
{
applicants = new ArrayList<String>();
}
public void addApplicant(String app)
{
applicants.add(app);
toArray();
}
public void toArray()
{
int x = applicants.size();
if (x == 0){ } else{
appArray=applicants.toArray(new String[x]);}
}
public void list() //Lists the arrayList
{
for (int i = 0; i<applicants.size(); i++)
{
System.out.println(applicants.get(i));
}
}
public void listArray() //Lists the Array[]
{
for(int i = 0; i<appArray.length; i++)
{
System.out.println(appArray[i]);
}
}
}
任何建議將非常感激!
首先,開始改變to'if appArray = applicants.toArray(新的String [X]);' – 2013-02-22 13:28:40