I am asking this question for my clarification.
I am having a for loop inside of which I have some inner method. when I used "i" in this inner method the IDE keeps asking me to make it "i" as final.
for(int i=0; i<array.size();i++) {
some innermethodcode(){
Log.e("array",""+array.get(i)); // it says me make it final;
}
What would happen if I declared "i" as global like
int i ;
; or what would be different if I declared "i" as
int i = 0;
And use it as
for(i=0; i<array.size();i++) {
some innermethodcode(){
Log.e("array",""+array.get(i)); // it says me make it final;
}
would it result in completly unpredictable values of "i" because the place that uses it is not executed the same time the loop runs ?
EDIT
I am very much knowing about how to get a final variable from a loop variable like this:
for (int i = 0; i < 10; i++) { final int j = i; // now you can use j instead }
My question is why i need to make final and what would happen if I declared it as global.
Please help me to clarify this.
Thanks in advance.