3

I have this interface:

public interface IModel extends Serializable{
    boolean isOnDb();       
}

I have an Object that implements the interface IModel :

public class Media implements Serializable, IModel {
   @Override
   public boolean isOnDb() {
      return isOnDb;
   } 
}

I want to create a List where I can put objects that implement the interface IModel. Something like this:

  List<? extends IModel> list= new ArrayList<>();
  Media media = new Media();
  list.add(m); 

the code above doesn't compile. But I have no error if I do :

  List<IModel> list= new ArrayList<>();
  Media media = new Media();
  list.add(m); 

What's the difference between List<? extends IModel> and List<IModel>? Thank you in advance

MDP
  • 4,177
  • 21
  • 63
  • 119

0 Answers0