Anonymous Class return to parent method

311 Views Asked by At

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.

private int doStuff(){

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

}
1

There are 1 best solutions below

3
Barefooter On

Create an Instance final variable inside doStuff() method and assign the value inside the anonymous class.