You can use
A.this.x
Since the anonymous Runnable
class is an inner class of the A
class.
The concept of shadowing determines that x
in
System.out.println(x);
is referring to the local method parameter variable x
, but that is not final
so you can't access it within the anonymous class, not in Java 7 and below at least. You can in Java 8, which may be confusing.
Don't use the same name for your variables in the same compilation unit.