2

I'm having the following classes/interfaces:

public class GenericViewModel<T extends AbstractDatabaseObject> {
    private Class<?> type;

    @SuppressWarnings("unchecked")
    public GenericViewModel(Class<?> cl) {

       type = cl;   
    }      
}

and a specialization:

public class PersonViewModel extends GenericViewModel<Person> implements IPersonViewModel{  
    public PersonViewModel() {
        super(Person.class);
    }

}

Now, my problem is in the presenter:

public class GenericPresenter implements IGenericView.IGenericViewListener {

    private GenericViewModel<AbstractDatabaseObject> model;
    private IGenericView view;

    public GenericPresenter(GenericViewModel<AbstractDatabaseObject> model, IGenericView view) {
        this.model = model;
        this.view = view;
        view.addListener(this);
    }
}

To be more precise, I cannot call the constructor of the super class with the given arguments:

public class PersonPresenter extends GenericPresenter {

    PersonViewModel model;
    IPersonView view;

    public PersonPresenter(PersonViewModel model, IPersonView view) {

        super(model, view); // Here is the problem. No such constructor in superclass found


    // IGenericView i = (IGenericView) view;  <-- this seems to work
    // GenericViewModel<AbstractDatabaseObject> m = model; <-- this doesn't


     }
}

What do I have to change?

2
  • 1
    Have you tried private GenericViewModel<? extends AbstractDatabaseObject> model;? Commented May 27, 2015 at 12:08
  • Have you tried to cast directly into the super : super( (GenericViewModel<AbstractDatabaseObject>) model, (IGenericView) view); Commented May 27, 2015 at 12:12

1 Answer 1

1

Try to change the GenericPresenter class in this way:

private GenericViewModel<? extends AbstractDatabaseObject> model;
private IGenericView view;

public GenericPresenter(GenericViewModel<? extends AbstractDatabaseObject> model, 
                        IGenericView view) {
    this.model = model;
    this.view = view;
    view.addListener(this);
}
Sign up to request clarification or add additional context in comments.

Comments

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.