如何从Java类内部的函数访问主类对象?

Sadeepdarshana

请阅读以下代码中的2条注释。

public class Field extends LinearLayout {
    public void init() {
        setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {

                // I want to access the main object 'Field' here(not the class, the object)
            }
        });

    // to be clear the object referred as 'this' from HERE should be accessed from where the above comment is.
    }
}

这可能吗?是否有关键字可以从对象内部的函数访问主类对象?

他们是

是的,您应该用来从匿名类实例中Field.this访问Field实例。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章