I was trying to declare a static variable inside a function, and Eclipse told me I can't do that. :-(
Ex.
This use of static is perfectly legal in C++, so I can't figure out why Java doesn't like it? I know I could move the static variable to the class level, but since it's only used in that one function, that would just clutter up the class namespace and isn't good encapsulation.
Is there any other way to do what I'm trying to do?
Ex.
Code:
class Blah
{
public void Func()
{
static int counter = 0;
++counter;
System.out.println( "This function was called " + counter + " times." );
}
}
Is there any other way to do what I'm trying to do?