我不断收到此错误“找不到符号 - 方法 isCompleted()”,但我已经声明了它。我做错了什么???
private boolean isCompleted;
public boolean isCompleted()
{
return isCompleted = true;
}
public int getJobsWaiting()
{
int count = 0;
int i = 0;
while (i < jobList.size())
{
if(!jobList.get(i).isCompleted())
{
count = count + 1;
}
i = i+1;
}
return count;
}
最佳答案
import java.util.ArrayList;
import java.util.List;
public class Jobs {
List<Job> jobList = null;
public void createJobs(){
jobList = new ArrayList<Job>();
// create three jobs
for(int index = 0; index < 3; index++){
jobList.add(new Job());
}
}
public List<Job> getJobs(){
return jobList;
}
public int getJobsWaiting()
{
int count = 0;
int i = 0;
while (i < jobList.size())
{
if(!jobList.get(i).isCompleted())
{
count = count + 1;
}
i = i+1;
}
return count;
}
class Job {
private boolean isCompleted;
public boolean isCompleted()
{
return isCompleted;
}
}
public static void main(String[] args) {
Jobs myJob = new Jobs();
myJob.createJobs();
System.out.println(myJob.getJobsWaiting()); // return 3
List<Job> jobs = myJob.getJobs();
for(int index = 0; index < 3; index++){
System.out.println(jobs.get(index).isCompleted());
}
}
}
jobList.get(i) 应该返回一个包含 isCompleted() 的对象。因此,请确保您调用的是正确的对象。
关于java - 错误“找不到符号 - 方法 isCompleted(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20313586/