The best solution is to give the fields meaningful and distinguishing names. But this is not always possible...
To get a field or an outer instance you can use
OuterClass.this.y;
or if the field is static
OuterClass.y;
Note: y
is often short for this.y
(depending on where y
actually is defined)
Similarly, to call an instance method of an outer class you need.
OuterClass.this.method();
or
OuterClass.method(); // static
Note: in Java 8 you have method references which might be instance based. e.g.
list.stream().filter(OuterClass.this::predicate);