A
Alessio
Hi to everyone. Sorry if this question has been asked before...
Is something like the code below legal? if yes, which are the
implications of making the variable i final?
for(final int i = 0; i < something; ++i) {
new AnonymousInnerClass() {
public void doSomething() {
...use i in some very creative way...
}
};
}
This code appears to work for me, but actually I would have expected
it to be in error since the loop might assign a new value to i on each
iteration, and the final keyword should forbid that. Am I missing
something? Will this code eventually make the computer explode?
Thanks for any insight on this...
cheers
Alessio Stalla
Is something like the code below legal? if yes, which are the
implications of making the variable i final?
for(final int i = 0; i < something; ++i) {
new AnonymousInnerClass() {
public void doSomething() {
...use i in some very creative way...
}
};
}
This code appears to work for me, but actually I would have expected
it to be in error since the loop might assign a new value to i on each
iteration, and the final keyword should forbid that. Am I missing
something? Will this code eventually make the computer explode?
Thanks for any insight on this...
cheers
Alessio Stalla