Java Generics : Obtaining a Class>?

后端 未结 3 1403
北荒
北荒 2021-01-18 08:08

I\'m having trouble using generics. Given the following example :

class A {
  public A(Class myType){
  }
}

class B extends A<         


        
3条回答
  •  迷失自我
    2021-01-18 08:21

    You can't possibly get a Class> except for Collection.class, because of type erasure. You'll have to use unsafe casts to cast a Collection.class to a Class> -- specifically, (Class>) (Class) Collection.class will do the job.

提交回复
热议问题