javac的爲int對我說:實際參數日期無法轉換通過方法調用轉換
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
,但在我的任務,理由是日期,不是int:
public Date nextTimeAfter(Date current) {
// may return null or DATE
}
下面是一個代碼-caller:
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不顯示任何錯誤,但編譯發誓(
什麼是「處理」? –
processed是迭代器當前項的foreach的本地值; – ovnia
向我們展示'Task'類的代碼。您發佈的'nextTimeAfter'方法似乎與拋出的異常不匹配 – SudoRahul