Given this situation where a lambda is inside a for loop I would expect the counter i to be effectively final.
The compiler complains that i is not effectively final
You have to remember that a for
loop actually equivalent to :
int i=0;
while(i < x.getBooks().size()){
//execute your block
i++;
}
So you see that i
is declared only once and updated therefore not effectively final.
It's a little unclear the relationship between x.getBooks()
and Book.getAuthors()
but apparently they have the same size? Without a better understanding, I don't think I can show you a better way to do it. But this might also show you that your design is poor.