How to pass an anon ref outer class to a method in an anon inner class in Java?
I have a method that makes an asynchronous call on the server - sendCall(some_args, callback) . The callback is represented by an anonymous class (let its name be OuterAnon ) and contains a method for the case of failure. A message box is created inside this method, and sendCall() is called each time the OK button is clicked. So I need to pass OuterAnon method again.
Here is the code demonstrating what I mean:
private void sendCall(MyData data, OuterAnon<Boolean> callback){} private void myCall(final MyData data) { sendCall(data, new OuterAnon<Boolean>() { public void onFailure(Throwable throwable) { final OuterAnon<Boolean> callback = this;
As you noticed, I take the link for the callback here:
final OuterAnon<Boolean> callback = this;
and use it here:
sendCall(new MyData("resend?"), callback);
But I want to avoid creating a ref and do a callback, for example:
sendCall(new MyData("resend?"), this);
Is there any way to do this in Java?
source share