Please, consider my code:
class A {
}
class B extends A {
}
class AWrapper<T extends A> {
}
class BWrapper<T extends B> extends AWrapper<T> {
}
So, I have C extends B etc, and CWrapper<T extends C> extends BWrapper<T> etc.
Now, I use these classes this way:
class Test {
private Class<? extends AWrapper<? extends A>> klass;//LINE X
public Test() {
this.klass = BWrapper.class;//LINE Z
}
}
At LINE X I need to set different classes - AWrapper, BWrapper, CWrapper etc. However, at LINE Z I get an error. Could anyone help to fix it?
Class<?>is the best you can do for the type ofklass.Class<AWrapper>is not a sub type ofClass<BWrapper>You can't assign one to the other. Generic aren't meant for this sort of problem.