首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java的反照和它的类加载机制

2013-04-26 
java的反射和它的类加载机制static?Class?forName(String?className)Returns the?Class?object associat

java的反射和它的类加载机制
static?Class<?>forName(String?className)Returns the?Class?object associated with the class or interface with the given string name.static?Class<?>forName(String?name, boolean?initialize,?ClassLoader?loader)Returns the?Class?object associated with the class or interface with the given string name, using the given class loader.

三参数的解释 如果initalize设为true,类型会在forName()方法返回前连接并初始化;如果是false,类型会被加载,可能会连接但是不会被明确的初始化。如果loader 为null则使用默认的加载器,也可以选用自定义的加载器。

两个forName()方法都返回Class实例的引用,代表被装载的类型。如果不能装载抛出ClassNotFoundException。即前提是类已经编译成class的字节码文件。

?

如果使用用户自定义的装载器,那么loadClass()方法就要调用?

?

Class<?>loadClass(String?name)Loads the class with the specified???binary name?.protected?Class<?>loadClass(String?name, boolean?resolve)Loads the class with the specified???binary name?.

这两个方法来装载新的请求的类型,如果找不到,会抛出ClassNotFoundException 异常。?



类装载的反向查找是去已经加载的类库中寻找权限定名的过程,如果没有就重新动态扩展,(就像一个map的映射方式去找的。)前提是类已经编译成class的字节码文件。

?

热点排行