匿名对象如何访问Java中TreeSelectionListener的超类?
this.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
// How do I access the parent tree from here?
}
});
# 1 楼答案
TreeSelectionListener
是一个接口,因此唯一的父类是Object
,您应该能够使用super
调用它如果您的意思是调用封闭类的某个方法,那么可以在方法中直接调用它
# 2 楼答案
你可以使用
OuterClass.this
:但是,如果只需要访问封闭实例中的成员,而不是获取实例本身的引用,则可以直接访问它: