I’m having trouble using generics. Given the following example :
class A<T> {
public A(Class<T> myType){
}
}
class B<E> extends A<Collection<E>> {
public B(Class<E> myEType){
super(???);
}
}
What ??? should be ?
Collection.class don’t work…
Collection<E>.class neither.
(Class<Collection<E>>)Collection.class do not work…
If there is a java generics guru, I need help… :/
You can’t possibly get a
Class<Collection<E>>except forCollection.class, because of type erasure. You’ll have to use unsafe casts to cast aCollection.classto aClass<Collection<E>>— specifically,(Class<Collection<E>>) (Class) Collection.classwill do the job.