简体   繁体   English

匿名类返回父方法

[英]Anonymous Class return to parent method

Is it possible to have an anonymous inner class return a value for a method it is contained in? 是否有可能让匿名内部类返回包含在其中的方法的值? For example, I want to do some calculations in something() , which is an anonymous inner class, and have doStuff() return that value. 例如,我想在something()做一些计算,这是一个匿名的内部类,并且让doStuff()返回该值。

private int doStuff(){

    Foo foo = new Foo(new Bar.Example() {
            @Override
            public void something() {
                ...
                //return int for doStuff()
            }
    });

}

doStuff()方法中创建一个Instance final变量,并在匿名类中分配值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM