0

In class Foo, I'm performing an HTTP post, returning to a callback:

class Foo {

    private static void send() {

        HttpPostRequest task = new HttpPostRequest(data, new HttpPostRequest.CustomCallback() {
            @Override
            public void completionHandler(Boolean success, String result) {

                // this doesn't work
                // this.anotherMethod();
            }
        });
        task.execute("https://foo.org");
    }

    private static void anotherMethod() {
      // i need to do things here...
    }

}

This callback works, however I need to call another method in the outer class scope. I can't figure out how to do this: How do I properly reference this outer scope?

0

1 Answer 1

1

When both methods are static you can simply call:

Foo.anotherMethod()

if both are not static, you can do:

Foo.this.anotherMethod()
Sign up to request clarification or add additional context in comments.

2 Comments

Will this also reference instance variables? Such as this.myVariable in the outer class instance?
@dthree that's the second option I mentioned (which is feasible only if both methods are not static). When a method is static it does not refer to any instance since it's a class-method not an instance-method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.