目录

ClassLoader getParent()

描述 (Description)

java.lang.ClassLoader.getParent()方法返回用于委派的父类加载器。 某些实现可能使用null来表示引导类加载器。 如果此类加载器的父级是引导类加载器,则此方法将在此类实现中返回null。

声明 (Declaration)

以下是java.lang.ClassLoader.getParent()方法的声明

public final ClassLoader getParent()

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回父ClassLoader

异常 (Exception)

SecurityException - 如果存在安全管理器且其checkPermission方法不允许访问此类加载器的父类加载器。

例子 (Example)

以下示例显示了java.lang.ClassLoader.getParent()方法的用法。

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018