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

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

  •  14-06-2023
  •  | 
  •  

Pergunta

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?

Foi útil?

Solução

You should use ModelLoader.this instead.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top