S
Sierra Bravo
Hi group
Is there some way to emulate in Java the semantics of the C-style
function-level static variable that preserves its value across function
calls ?
void show()
{
static int i = 0;
printf("Value is %d",i); // Prints 1.2.3... on multiple calls
to show()
i++;
}
I can perhaps use an instance variable, but it would be visible from
all other methods as well (and also creates a dependency on a variable
outside the method). I tried "static" itself in Java, but the compiler
complains loudly....
sb
Is there some way to emulate in Java the semantics of the C-style
function-level static variable that preserves its value across function
calls ?
void show()
{
static int i = 0;
printf("Value is %d",i); // Prints 1.2.3... on multiple calls
to show()
i++;
}
I can perhaps use an instance variable, but it would be visible from
all other methods as well (and also creates a dependency on a variable
outside the method). I tried "static" itself in Java, but the compiler
complains loudly....
sb