This week's book giveaways are in the Scala and Android forums. We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line! See this thread and this one for details.
That's because the final keyword prohibits a final variable from being reassigned, but in the above loop, you're both declaring and assigning the final variable. So on each iteration of the loop, the percent variable loses its scope when the iteration ends, and on the next iteration, it's like you're declaring a brand new variable in a new scope, and its being assigned as soon as it is declared. This happens on every iteration. So it's legal.
If you happen to change your code to this:
Then you can see the compiler error that final variable can't be reassigned. Now the scope of the percent variable is same throughout the all the iterations, and you can't reassign in the same scope. Hope you got the difference.
posted 11 months ago
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!