mercredi 12 avril 2017

List with generic type [duplicate]

i have this data types

    public interface Adaptable {
        public void doSomething();
    }    

    public class MyObject implements Adaptable {
        public String name;

        @Override
        public void doSomething(){}
    }

and i want to make a ArrayList of MyObject type and send to a class that wait for a ArrayList of Adaptable

        List<MyObject> objects = new ArrayList<>();
        objets.add...

        List<Adaptable> items = objects;

and i get this error

incompatible types: List< MyObject > cannot be converted to List< Adaptable >

Aucun commentaire:

Enregistrer un commentaire