3

MyClass.java

protected LinkedBlockingDeque<JobSet> currentWork = new LinkedBlockingDeque<JobSet>();

public LinkedBlockingDeque<JobSet> getCurrentWork() {
    return currentWork;
}

用法

public boolean completeAllWork(CompleteWorkRequest request) {
    for (JobSet jobSet : getCurrentWork()) {
        //if it's approved, find the workflow process it needs to go to next and put it there
        if (request.getApprovedJobSets().contains(jobSet.getUuid().toString())) {
            sendToNextWorkflowProcess(jobSet);
        } else {
            getCurrentWork().remove(jobSet);
            logger.info("Rejected JobSet: " + jobSet.getUuid());
        }
    }

    getWorkFromQueue();

    return true;
}

它期待一个JobSet但得到一个Object。我似乎很清楚它正在返回正确的对象,那么我错过了什么?

Error: java: incompatible types
  required: com.production.model.JobSet
  found:    java.lang.Object
4

4 回答 4

2

根据评论:使用 an Iterator应该可以解决问题。我的猜测是在迭代列表并同时删除一个项目时存在干扰,导致循环读取已删除的值。

于 2013-07-26T14:49:15.557 回答
0

您无法从到目前为止发布的代码中得到您提到的错误。这编译没有错误:

import java.util.concurrent.LinkedBlockingDeque;
import java.util.Collection;

class dummy {
    static class JobSet {public Object getUuid() {return null;}}
    static class CompleteWorkRequest {public Collection getApprovedJobSets() {return null;}};
    void getWorkFromQueue() {}
    void sendToNextWorkflowProcess(JobSet js) {}


    protected LinkedBlockingDeque<JobSet> currentWork = new LinkedBlockingDeque<JobSet>();

    public LinkedBlockingDeque<JobSet> getCurrentWork() {
        return currentWork;
    }

    public boolean completeAllWork(CompleteWorkRequest request) {
        for (JobSet jobSet : getCurrentWork()) {
            //if it's approved, find the workflow process it needs to go to next and put it there
            if (request.getApprovedJobSets().contains(jobSet.getUuid().toString())) {
                sendToNextWorkflowProcess(jobSet);
            } else {
                getCurrentWork().remove(jobSet);
                //logger.info("Rejected JobSet: " + jobSet.getUuid());
            }
        }

        getWorkFromQueue();

        return true;
    }
}
于 2013-07-26T14:47:29.773 回答
0

可能是您的方法之一被声明为返回 aLinkedBlockingDeque而不是 a LinkedBlockingDeque<JobSet>

  • 检查声明的返回类型getApprovedJobSets()
  • 查看方法中的代码getWorkFromQueue(),可能是那里抛出了错误。

此外,编译器是否给出任何“未经检查的类型”或“原始类型”警告?

于 2013-07-26T14:38:38.593 回答
0

实际上,如果我理解正确,您的错误不是来自 return 语句,而是来自 else 语句中的两行。 我认为您应该查看这些方法返回的内容并尝试修改它们

于 2013-07-26T14:39:12.450 回答