-2

This code has been giving me problems. all I want to do is create methods that will allow me to add generics to this array list. Using an Array List is not necessary if there is a better class that works well with generics. before I get useless answers these objects are initialized in the constructor of the object they are in. and the getters and setters exist. the problem is that the .add() method in array list is not accepting generics

private ArrayList<? extends Inputable> inputSubscriber;
private ArrayList<? extends Updateable> updateSubscriber;
private ArrayList<? extends Renderable> renderSubsciber;

public <e extends Inputable> void subscribeToInput(e inputable){
    this.getInputSubscriber().add(inputable);
}

public <e extends Updateable> void subscribeToUpdate(e updateable){
    this.getUpdateSubscriber().add(updateable);
}

public <e extends Renderable> void subscribeToRender(e renderable){
    this.getRenderSubsciber().add(renderable);
}
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 3
    You don't need any of that `extends` stuff. You should be using `Inputable`, `Updateable`, and `Renderable` directly. – user2357112 Jul 05 '17 at 23:47
  • yes thank you, I just realized that my mistake was stupid and already provided an answer. thank you for your prompt reply however! I just had a moment... – Jordan Doerksen Jul 05 '17 at 23:50

1 Answers1

-2

This was a stupid over sight on my part. I am not sure how this problem lasted me long enough to ask the question here. but for those of you having the same issue this problem does not need generics and can be solved like this. I over complicated things since inputable and others are interfaces.

private ArrayList<Inputable> inputSubscriber;
private ArrayList<Updateable> updateSubscriber;
private ArrayList<Renderable> renderSubsciber;

public void subscribeToInput(inputable){
    this.getInputSubscriber().add(inputable);
}

public void subscribeToUpdate(updateable){
    this.getUpdateSubscriber().add(updateable);
}

public void subscribeToRender(renderable){
    this.getRenderSubsciber().add(renderable);
}