[英]How to define variable of generic class reference to pass the class into a method
在genric中獲取錯誤以在Java中定義genric類型變量
用通用類型定義變量
通用,普通,主類的示例
//Generic Class
public class A <T> {
T t;
//getter setter
}
//Normal class
public class B {
//Some variables
}
//Main Class
public class C {
public static void main(String[] args) {
//Fine with normal class
doSomeOpration(B.class);
//Call doSomeOpration with genric class
doSomeOpration(A<B>.class); //getting error not resolved A<B> generic type
}
public <T> static void doSomeOpration(Class<T> clazz) {
//Do Some opration with clazz
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.