Accessing this of outerclass from anonymous inner class where outerclass has a generic

StackOverflow https://stackoverflow.com/questions/22390732

  •  14-06-2023
  •  | 
  •  

문제

I have some code like this:

public class ModelLoader<T extends Model> {
    public ArrayList<T> fromJson(JSONArray jsonObjects) {
         // blah blah blah
    }

    public void getAll(final OnRequestCompleted<T> callback) {
        client.get(endpoint, null, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(JSONArray resp) {
                // I want to call the fromJson method here
            }

        });
    }
}

I have seen in various places that I can use OuterClass.this, which in this case would be ModelLoader<T>.this but that gives me syntax error.

How can I do this?

도움이 되었습니까?

해결책

You should use ModelLoader.this instead.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top