Generics are not covariant so you can't set to Class<Blah>
object of type Class<Inter>
. Think about it. If you would be able to use List<Fruit> list = new ArrayList<Apple>()
then via list
you would be able to add not only Apples but also other Fruits. Would that be OK?
To solve this problem try changing Class<Blah>
to Class<? extends Blah>
You can also change your Dummy
class to use generic type T
class class Dummy<T extends Blah> {
Class<T> interfaceType;
public void setInterfaceType(Class<T> input) {
this.interfaceType = input;
}
}
and use it like
Dummy<Inter> dummyObj = new Dummy();
dummyObj.setInterfaceType(Inter.class);