W
W
Web__Nikita032020-02-14 19:47:56
Java
Web__Nikita03, 2020-02-14 19:47:56

How to properly use generic types?

I need the attach method to accept a class that inherits from BaseCompatActivity. What did I do wrong because Android Studio throws an error

public interface BaseMvpPresenter <T extends BaseCompatActivity>{
    boolean isAttached = false;
    void attach(T view);
    void detach();
}

And the main presenter himself
public class BasePresenter <T extends BaseCompatActivity> implements BaseMvpPresenter {

    private T view;
    private boolean isAttached = false;

    @Override
    public void attach(T view) {
        this.view = view;
        isAttached = true;
    }

    @Override
    public void detach() {
        view = null;
        isAttached = false;
    }
}

Strongly do not kick, I only recently got acquainted with generic types.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elmo Sputterspark, 2020-02-14
@Sputterspark

The text of the error says that you did something wrong.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question