java中的classloader

Because class loaders exist, the Java run time does not need to know anything about files and file systems when running Java programs.

A class loader starts by being a subclass of java.lang.ClassLoader. The only abstract method that must be implemented is loadClass(). The flow of loadClass() is as follows:

    Verify class name.
    Check to see if the class requested has already been loaded.
    Check to see if the class is a "system" class.
    Attempt to fetch the class from this class loader's repository.
    Define the class for the VM.
    Resolve the class.
    Return the class to the caller.
    

In Java, a class is identified by its fully qualified class name. The fully qualified class name consists of the package name and the class name. But a class is uniquely identified in a JVM using its fully qualified class name along with the instance of the ClassLoader that loaded the class. Thus, if a class named Cl in the package Pg is loaded by an instance kl1 of the class loader KlassLoader, the class instance of C1, i.e. C1.class is keyed in the JVM as (Cl, Pg, kl1). This means that the two class loader instances (Cl, Pg, kl1) and (Cl, Pg, kl2) are not one and the same, and classes loaded by them are also completely different and not type-compatible to each other.

例如:图 Multiple ClassLoaders loading the same Target class in the same JVM

Target target3 = (Target) target2;
在运行时会抛出ClassCastException


http://onjava.com/pub/a/onjava/2005/01/26/classloading.html?page=1

http://www.javaworld.com/javaworld/jw-10-1996/jw-10-indepth.html?page=1

http://www.ibm.com/developerworks/java/tutorials/j-classloader/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值