iam*_*ind 3 java eclipse compilation protected access-specifier
我在下面用Eclipse ide编写的代码:
public interface X
{
final public static int SOME_CONST = 0;
}
public class Handle implements X
{
protected void methodHandle () { }
//...
}
public class User implements X
{
Handle handle = new Handle();
private void methodUser ()
{
Y y = new Y() // anonymous inner class
{
public void methodY ()
{
handle.methodHandle (); // <--- why this is NOT giving error ?
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
即使Handle.methodHandle ()是protected,它仍然可以从匿名内部class方法的内部方法调用?它为什么会发生,我错过了什么?Handle和之间的唯一关系User是它们是implement相同的X.