public class TestThread
{
public static void main (String [] args)
{
Foo f = new Foo();
Thread t = new Thread(new Runnable()
{
public void run()
{
f.doStuff();
}
});
Thread g = new Thread()
{
public void run()
{
f.doStuff();
}
};
t.start();
g.start();
}
}
class Foo
{
public void doStuff()
{}
}
We Know that local variable of a function is not in scope while other method is running and we also know that method local inner class can only use final variable of the method. My question is why this code compiles and runs even though f is local variable and it is not even final. It should be out of scope for the anonymous inner classes...