0

So I'm getting the following error in eclipse and I am not understanding what is the problem:

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

The code minActiveDutyCycles[i++]; on line B is underlined with red

for code:

    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);
letter Q
  • 14,735
  • 33
  • 79
  • 118
  • Do you know what a final variable is? Do you know what a non-final variable is? – Sotirios Delimanolis May 30 '15 at 20:52
  • 1
    It's because Java (pre 8, at least) doesn't support true closures. More info in [this thread](http://stackoverflow.com/questions/1299837/cannot-refer-to-a-non-final-variable-inside-an-inner-class-defined-in-a-differen). – Mick Mnemonic May 30 '15 at 20:54

0 Answers0