GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on varargs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on varargs" Watch "Question on varargs" New topic
Author

Question on varargs

victor kamat
Ranch Hand

Joined: Jan 10, 2007
Posts: 247
Consider the following code:

This code compiles fine and puts out the expected output.
What has me confused is the "final" int the second for loop.
I would have thought that the code would not compile.
If we make k final in the 1st loop, code does not compile.
Can somebody explain this to me.
[ January 21, 2007: Message edited by: Barry Gaunt ]
victor kamat
Ranch Hand

Joined: Jan 10, 2007
Posts: 247
I have answered my own question. In the loop body cannot change value of i

void prt(int... par)
{
for(final int i : par)
{
// in loop body cannot change i
}
}
[ January 21, 2007: Message edited by: Barry Gaunt ]
 
GeeCON Prague 2014
 
subject: Question on varargs