无法引用封闭范围中定义的非最终局部变量

时间:2015-05-30 20:51:38

标签: java scope final

所以我在eclipse中遇到以下错误,我不明白是什么问题:

错误: Cannot refer to the non-final local variable minActiveDutyCycles defined in an enclosing scope

B行的代码minActiveDutyCycles[i++];带有红色

下划线

代码:

    double[] minActiveDutyCycles = c.getMinActiveDutyCycles(); // LINE A <==== WHY DOES THIS VARIABLE NEED TO BE FINAL for code at LINE B???

    ArrayUtils.setIndexesTo(boostInterim, ArrayUtils.where(activeDutyCycles, new Condition.Adapter<Object>() {
        int i = 0;
        @Override public boolean eval(double d) { return d > minActiveDutyCycles[i++]; } // LINE B
    }), 1.0d);

0 个答案:

没有答案