Ambiguous name: inherited 'identifier' and outer scope 'identifier' — an explicit 'this' qualifier is required
The compiler detected reference to a variable or method from within an inner class that is defined in both its outer class and its superclass. The compiler cannot determine which variable or method is to be used. You can reference the outer class variable or method by using class.this.name, where class is the name of the outer class whose variable or method you wish to reference and name is the variable or method name. To reference the superclass variable or method you can use the this super keyword before the reference.
The following example illustrates this error:
class NotSimple{
int var1 = 20;
}
public class Simple{
int var1 = 10;
class InnerClass extends NotSimple{
int var2 = var1;
//error: cannot determine which 'var1' to use
}
}
The following example illustrates how to resolve name ambiguity between the outer class and superclass variables:
class NotSimple{
int var1 = 20;
}
public class Simple{
int var1 = 10;
class InnerClass extends NotSimple{
int var2 = Simple.this.var1;
//this is OK and references the outer class variable
int var3 = super.var1;
//this is OK and references the superclass variable
}
}