getting IllegalAccessException when accessing a protected method from parent from inner class

Posted by EnToutCas on Stack Overflow See other posts from Stack Overflow or by EnToutCas
Published on 2010-06-11T18:12:24Z Indexed on 2010/06/11 18:33 UTC
Read the original article Hit count: 232

Filed under:
|

I got a very weird problem and a weird solution:

class Parent {
    protected void aProtectedMethod() { doSomething(); }
} 

class Child extends Parent {
    void anotherMethod() {
      new SomeInterface() {
          public void interfaceMethod() {
              aProtectedMethod();
          }
      };
    }
}

When child.anotherMethod() is run, I got IllegalAccessException at myProtectedMethod(), saying my inner class doesn't have access to the Parent class...

However, if I add:

protected void aProtectedMethod() { super.aProtectedMethod(); } 

in my Child class, everything is fine...

I wonder why this is?

© Stack Overflow or respective owner

Related posts about java

Related posts about gwt