以下のコードでは、なぜインライン クラスの run() が外側のクラス変数であるセマフォにアクセスできるのか疑問に思っています (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");
}
}
};
セマフォ参照が final と宣言されていないため、Eclipse がコンパイル エラーにフラグを立てることを期待していました。