Javac 对我说:
error: method nextTimeAfter in class Task cannot be applied to given types;
if (processed.nextTimeAfter(start) != null
^
required: int
found: Date
reason: actual argument Date cannot be converted to int by method invocation conversion
但在我的任务中,参数是日期,而不是整数:
public Date nextTimeAfter(Date current) {
// may return null or DATE
}
这是一个代码调用者:
public static Iterable<Task> incoming(Iterable<Task> tasks, Date start,
Date end) {
if (start.before(end))
return tasks;
LinkedList<Task> result = new LinkedList<Task>();
for (Task processed : tasks) {
if (processed.nextTimeAfter(start) != null
&& processed.nextTimeAfter(start).before(end)) {
result.add(processed);
}
}
return result;
}
此外,任务类
public class Task {
private Date time;
private Date startTime;
private Date repeatInterval;
private Date endTime;
//...getters-setters
public Date nextTimeAfter(Date current) {
if (current == null)
throw new IllegalArgumentException("Argument <current> is NULL");
if (!isActive() || (!isRepeated() && current.after(getTime())))
return null;
Date result = getStartTime();
while (result.after(current)) {
Date temp = (Date) result.clone();
temp.setTime(temp.getTime() + getRepeatInterval().getTime());
if (temp.after(getEndTime()))
return null;
result.setTime(result.getTime() + getRepeatInterval().getTime());
}
return result;
}
}
很奇怪,为什么会这样。Eclipse 没有显示任何错误,但编译器发誓(