美文网首页
关于ClassLoader

关于ClassLoader

作者: 龙剑灵 | 来源:发表于2019-12-06 01:51 被阅读0次
image.png
public static void main(String[] args) throws IOException {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    String resourceName = "jvm/classloader/MyTest12.class";
    Enumeration<URL> urls = classLoader.getResources(resourceName);
    while (urls.hasMoreElements()) {
      URL url = urls.nextElement();
      System.out.println(url); // file:/E:/gitSpace/jdk8/out/production/classes/jvm/classloader/MyTest12.class
    }
    System.out.println("--------------------------------");

    Class<?> clazz = MyTest14.class;
    Class<?> clazz1 = String.class;
    System.out.println(clazz.getClassLoader()); //sun.misc.Launcher$AppClassLoader@18b4aac2
    System.out.println(clazz1.getClassLoader()); //Bootstrap在.. 统一用 null 表示
  }

输出结果是:
file:/E:/gitSpace/jdk8/out/production/classes/jvm/classloader/MyTest12.class
sun.misc.Launcher$AppClassLoader@18b4aac2
null

相关文章

网友评论

      本文标题:关于ClassLoader

      本文链接:https://www.haomeiwen.com/subject/wkksgctx.html