R
Razvan
Hi !
Today I tried something like:
class Rebo {
int StaticLocalVar()
{
static int counter = 0;
return counter++;
}
}
And to my surprise the compiler complained because the counter is
static:
name/mihaiu/test/CTest.java:69: illegal start of expression
static int counter = 0;
^
1 error
What if you need to keep the counter value between calls to
StaticLocalVar() ? Like it is, the only option is to transform the
local variable in an attribute. (while removing the static qualifier)
But, if the variable has meaning only for the function itself ? Why
putting it in the class ? Is there another way ?
Regards,
Razvan
Today I tried something like:
class Rebo {
int StaticLocalVar()
{
static int counter = 0;
return counter++;
}
}
And to my surprise the compiler complained because the counter is
static:
name/mihaiu/test/CTest.java:69: illegal start of expression
static int counter = 0;
^
1 error
What if you need to keep the counter value between calls to
StaticLocalVar() ? Like it is, the only option is to transform the
local variable in an attribute. (while removing the static qualifier)
But, if the variable has meaning only for the function itself ? Why
putting it in the class ? Is there another way ?
Regards,
Razvan