国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

java之反射進階

2019-11-08 00:42:44
字體:
來源:轉載
供稿:網友

我們反射通常使用第一種方式,首先來看看Class.forName(clssName): 注意:傳入的className必須是類的全路徑,否則會報錯java.lang.ClassNotFoundException

public static Class<?> forName(String className) throws ClassNotFoundException { return forName0(className, true, ClassLoader.getCallerClassLoader()); }

通過調用forName0方法,使用ClassLoader.getCallerClassLoader()來加載ClassLoader

// Returns the invoker's class loader, or null if none. // NOTE: This must always be invoked when there is exactly one intervening // frame from the core libraries on the stack between this method's // invocation and the desired invoker. static ClassLoader getCallerClassLoader() { // NOTE use of more generic Reflection.getCallerClass() Class caller = Reflection.getCallerClass(3); // This can be null if the VM is requesting it if (caller == null) { return null; } // Circumvent security check since this is package-PRivate return caller.getClassLoader0(); }

在獲取ClassLoader調用claser.getClassLoader0() 這是一個私有包,可以避免安全檢查。

// Package-private to allow ClassLoader access native ClassLoader getClassLoader0();

1、ClassLoader到底是個什么東西


上一篇:JAVA總結

下一篇:Java面試題全集(下)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 揭阳市| 府谷县| 潼南县| 天水市| 内黄县| 沙湾县| 巴彦县| 同德县| 青冈县| 西昌市| 大宁县| 林口县| 邓州市| 密山市| 滦平县| 长葛市| 宿迁市| 石河子市| 中江县| 余干县| 河间市| 永修县| 汽车| 长泰县| 汉源县| 深泽县| 望奎县| 侯马市| 大连市| 右玉县| 调兵山市| 合山市| 吉安市| 长白| 青河县| 左云县| 庆云县| 白水县| 洛浦县| 托克托县| 孝感市|