Search code examples
javainner-classes

how to refer same method from (non static) inner to outer class


I have a (non static) inner class and have a same method within both the inner and the outer class. How can I call the outer method within the inner method?

class User{

    public void call() {
        ...
    }
    
    public class Admin{
        public void call() {
            // I want to refer to User#call, not to Admin#call()
           // super.call() does not work here, because no inheritance
            call(); // refers to Admin#call
        }
    }
}

Solution

  • By applying the class name to "this":

    User.this.call()