In the code below, I am wondering why the run() in the inline class is able to access the outer class variable - semaphore (even though it is not declared final).
private Semaphore semaphore = new Semaphore(bufferSize);
private Runnable producerRunnable = new Runnable(){
@Override
public void run()
{
try
{
semaphore.acquire();
}
catch(InterruptedException e)
{
System.out.println("producer was interrupted while trying to acquire semaphore");
}
}
};
I expected Eclipse to flag a compilation error - since semaphore reference is not declared final