日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ParameterizedTypeImpl

發布時間:2023/12/1 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ParameterizedTypeImpl 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
關于“通過反射獲得泛型的參數化類型”的問題: 下面是張老師 通過反射獲得泛型的參數化類型的一段代碼import java.util.*; import java.lang.reflect.*;public class GenericalReflection { private Vector<Date> dates = new Vector<Date>(); public void setDates(Vector<Date> dates) { this.dates = dates; } private static void applyGeneric(Vector<String> v){}public static void main(String[] args)throws Exception { Method methodApply = GenericalReflection.class.getDeclaredMethod("applyGeneric", Vector.class);ParameterizedType pType = (ParameterizedType)(methodApply .getGenericParameterTypes())[0]; /*上面這句methodApply .getGenericParameterTypes()返回的是一個Type類型的對象數組。據java API上說,
Type是一個接口,這個接口只有一個實現類,就是 Class 類。所以我就認為methodApply .getGenericParameterTypes()得到的Type類型的數組
其本質應該是一個Class類型的數組。然后應該說,這句methodApply .getGenericParameterTypes()經過 (ParameterizedType)
強制類型轉換后能夠調用 getRawType()、getActualTypeArguments()等方法說明在Class類內部實現了ParameterizedType接口并重寫里面的所有方法,
但是Class類的java API上,并沒有實現過ParameterizedType接口,并且在Class類的源代碼中也沒有見到Class類實現ParameterizedType接口。
那么沒有類去實現ParameterizedType接口,怎么可去調用其方法呢??求解!!
*/ System.out.println("setDates(" + ((Class) pType.getRawType()).getName() +
"<" + ((Class) (pType.getActualTypeArguments()[0])).getName() + ">)" );System.out.println((methodApply .getGenericParameterTypes()).getClass());} }

解答:

通過插入語句System.out.println(methodApply .getGenericParameterTypes()[0].getClass());

得到打印結果為class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
通過反編譯ParameterizedTypeImpl.class文件發現ParameterizedTypeImpl類實現了ParameterizedType接口,而在java的api文檔中并沒有涉及到sun包中的內容。 原來是ParameterizedTypeImpl類實現了ParameterizedType接口。
methodApply .getGenericParameterTypes()得到的本質上并不是一個Class類型的數組,而是一個ParameterizedTypeImpl類型的數組。
我又看了看rt.jar包。在這個包中 有ParameterizedTypeImpl這個類。

轉載于:https://www.cnblogs.com/wuqingdong/archive/2012/10/02/2710238.html

總結

以上是生活随笔為你收集整理的ParameterizedTypeImpl的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。