I'm not sure I'm seeing how a method scoped static would be used.
Is the idea that the value would maintain its value between calls to
the method, but keep the scope local to the method? If so how
would you keep the declaration from overwriting the previously set
value?
It would behave exactly like a private static. It would be
initialised to 0/null. However, it would be declared in a method, and
any references to it outside that method would be illegal, detected an
compile time.
You would use it for example in
void myMethod ()
{
static Random wheel;
// first use init.
if( wheel == null ) wheel = new Random();
for (int i=0;i<100;i++)
{
System.out.println( wheel.nextInt( 6 ) );
}
}
You are declaring that wheel is purely for the use of myMethod, but
other than that in is like a private static.
To allow one-time initialisation would get fairly hairy. That is why I
side-stepped the issue. Perhaps inability to init is a reasonably
easily defined way is why Sun did not allow this. It would be a wart
no matter how it was handled.
Another syntax would be something like this where you declare outside
the method.
private to myMethod static Random wheel = new Random();
you could also have private instance methods too:
private to myMethod Random wheel = new Random();