Dave Tolls wrote:Surely you're just passing 'this' in?
Agreed. It doesn't make sense. The OP is saving the instance of the anonymous inner class, in a local reference variable, so that the instance of the anonymous inner class can access it... in other words, the anonymous inner class is trying to access a reference to itself. This is what the "this" variable is used for.
As for more details of the circular dependency issue... the instance of the inner class is trying to access a local variable of the outer class method. For this to work, the local variable has to be effectively final *and* assigned before the inner class is instantiated. This means that you need to instantiate the inner class *and* assign it to the reference variable -- and do so before you instantiate the inner class. This is, of course, not possible.