Java ClassLoader getParent()方法

java.lang.ClassLoader.getParent() 方法返回的父类加载器委托。一些实现可能使用null表示引导类加载器。此方法将返回在这种实现null,如果这个类加载器的父是引导类加载器。

1 语法

public final ClassLoader getParent()

2 参数

3 返回值

此方法返回的父类加载器。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * Java ClassLoader getParent()方法
 */
import java.lang.*;

public class ClassLoaderDemo {

  public static void main(String[] args) throws Exception {
     
    Class cls = Class.forName("ClassLoaderDemo");

    // returns the ClassLoader object associated with this Class
    ClassLoader cLoader = cls.getClassLoader();
    
    System.out.println(cLoader.getClass());
    
    // returns the parent ClassLoader
    System.out.println(cLoader.getParent());
  }
}

输出结果为:

class sun.misc.Launcher$AppClassLoader
sun.misc.Launcher$ExtClassLoader@35ce36

 

热门文章

优秀文章