Anonymous inner classes have a type, but not a name.
You can access fields not specified by the specified supertype. However, after assigning a variable of type named, the interface is lost.
Obviously, you can access the fields inside the inner class. One way to add code is through the instance initializer:
final AtomicInteger y = new AtomicInteger(); new Runnable() { int x; { x = 5; doRun(this); y.set(x); } public void run() { ... blah ... } };
The value returned by the anonymous internal expression of the class is of an anonymous type, so you have one chance to use it outside the class itself:
final int y = new Runnable() { int x; { x = 5; doRun(this); } public void run() { ... blah ... } }.x;
You can also pass it using a method declared similarly:
<T extends Runnable> T doRun(T runnable);
Tom Hawtin - tackline
source share