Java generics: get class >?

I'm having trouble using generics The following examples are given:

class A<T> {
  public A(Class<T> myType){
  }
}

class B<E> extends A<Collection<E>> {
  public B(Class<E> myEType){
    super(???);
  }
}

what??? should? Collection. Class does not work... Collect < E > Class is neither (class < collection < E > >) Class doesn't work

If there is a Java generics master, I need help...:/

Solution

You can't get class < collection < E > > except collection Class, because the type is erased You must use an unsafe cast to convert the collection Class cast to class < collection < E > > – specifically, (class < collection < E > >) (class) collection Class will finish the work

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>