Created
March 14, 2019 01:28
-
-
Save leonardotrp/4e80a10a51bea270c124be02a8f9dfb9 to your computer and use it in GitHub Desktop.
A doubt about the java keyword modifier 'final'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int bestIndex = 0; | |
| IntStream.range(0, population.size()).forEach(idxIndividual -> { | |
| Individual individual = population.get(idxIndividual); | |
| double x = 0, y = 0; | |
| for (int idxId = 0; idxId < individualSize; idxId++) { | |
| x += eigenvectors.getEntry(idxId, 0) * individual.get(idxId); | |
| y += eigenvectors.getEntry(idxId, 1) * individual.get(idxId); | |
| } | |
| projectionsSeries[idxIndividual] = new double[] {x, y}; | |
| if (population.getBest() == individual) | |
| bestIndex = idxIndividual; // PROBLEM HERE!!! | |
| }); | |
| // 1º error: Local variable bestIndex defined in an enclosing scope must be final or effectively final | |
| // ... put 'final int bestIndex = 0;' (line 1) | |
| // 2º error: The final local variable bestIndex cannot be assigned. It must be blank and not using a compound assignment | |
| // AND NOW?! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment