0

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

しかし、私の仕事では、引数は int ではなく Date です:

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;
    }

さらに、 Task クラス

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 はエラーを表示しませんが、コンパイラは (

4

2 に答える 2

1

あなたが追加して今まで言ったことから判断すると、私は以前の予感に行きます:プロジェクトをコンパイルしている間(あなたは単に「javac」または何か他のことをしていますか?)、Taskクラスを再コンパイルしておらず、コンパイラは古いバージョンを使用していますそのメソッドは、日付ではなく int を受け入れます (私が尋ねたように: そのようなバージョンはありましたか?)。

クラスパスとコンパイル オプションは Eclipse で適切に設定する必要があるため、問題はありません。

これを修正するには、他のコードをコンパイルする前に Task クラスを再コンパイルしてください。

于 2013-10-18T18:12:55.153 に答える
0

エラーメッセージは、実際には次のものが必要であると言っていnextTimeAfterますint:

required: int <-- what java expected
found: Date   <-- what you did

あなたは合格しましたdate。を渡す必要がありintます。

次のようなものを呼び出しstart.getTime()/1000て int に変換できます

于 2013-10-18T17:56:32.480 に答える