I have one interface IMyInterface. A set of classes that implements this interface : Class1, Class2…
Now i want to create a Hashtable that stores any class implementing IMyInterface.
Hashtable<String,? extends IMyInterface> ht = new Hashtable<String,? extends IMyInterface>();
ht.add("foo",new Class1());
The compiler complains that it cannot instiate ht and that it cannot add Class1 because
the add method is not defined to do so. add method expects IMyInterface :\
How can i do ?
Simply use:
Given that
Class1implementsIMyInterface.