I\'m having trouble using generics. Given the following example :
class A {
public A(Class myType){
}
}
class B extends A<
You can't possibly get a Class<Collection<E>>
except for Collection.class
, because of type erasure. You'll have to use unsafe casts to cast a Collection.class
to a Class<Collection<E>>
-- specifically, (Class<Collection<E>>) (Class) Collection.class
will do the job.
class A<T> {
public A(Class<T> myType){
}
}
class B<E> extends A<Collection<E>> {
public B(Class<Collection<E>> myEType){ // <-- this is the changed line
super(myEType);
}
}
Try this:
class A<T> {
public A(Class<?> myType){
}
}
class B<E> extends A<Collection<E>> {
public B(Class<E> myEType){
super(myEType);
}
}
If satisfied, please mark this answer correct.