0
我有一個構造函數:使用參數向類對象的ArrayList添加?
Candidate(String name, int numVotes)
{
this.name = name;
this.numVotes = numVotes;
}
我做了這個類的一個ArrayList:
List <Candidate> election = new ArrayList<Candidate>();
我想這一類的多個對象添加到ArrayList。我已經試過這一點,但它不工作:
election.add("John Smith", 5000);
election.add("Mary Miller", 4000);
它拋出一個編譯器錯誤,指出:
The method add(int, Candidate) in the type List<Candidate> is not applicable for the arguments (String, int)
我在做什麼錯?任何幫助,將不勝感激。