利用反射機制查看ArrayList類的信息

public class OutString {


public static void main(String[] args) throws ClassNotFoundException {
Class<?> clazz = Class.forName("java.util.ArrayList");//獲取ArrayList的類對象
System.out.println("累的標準名稱爲:"+clazz.getCanonicalName());
System.out.println("累的修飾符爲:"+Modifier.toString(clazz.getModifiers()));
TypeVariable<?>[] typeVariables = clazz.getTypeParameters();
System.out.println("類的泛型參數爲:");
if(typeVariables.length>0){
for(TypeVariable<?> typeVariable:typeVariables){
System.out.println(typeVariable+"\t");
}
}
Type[] interfaces = clazz.getGenericInterfaces();
System.out.println("類的所有接口爲:");
if(interfaces.length>0){
for(Type type:interfaces){
System.out.println(type+"\t");
}
}
Type superClass = clazz.getGenericSuperclass();
System.out.println("類的所有繼承類爲:");
if(superClass!=null){
System.out.println(superClass);
}
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章