我有以下用 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 ?
}
}
}
}
即使Handle.methodHandle ()
是protected
,它仍然可以从匿名内部class
方法的内部方法调用?为什么会这样,我错过了什么吗?Handle
和之间的唯一关系User
是它们是implement
相同的X
。