Java类类getClassLoader()方法及示例

Java类类getClassLoader()方法及示例类的类getClassLoader()方法(ClassclassgetClassLoader()method)getClassLoader()methodisavailableinjava.langpackage.getClassLoader()方法在java.lang包中可用。getClassLoader()methodisusedtoreturnthe…

大家好,又见面了,我是你们的朋友全栈君。

类的类getClassLoader()方法 (Class class getClassLoader() method)

  • getClassLoader() method is available in java.lang package.

    getClassLoader()方法在java.lang包中可用。

  • getClassLoader() method is used to return the ClassLoader that loads the class or interface.

    getClassLoader()方法用于返回加载类或接口的ClassLoader。

  • getClassLoader() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    getClassLoader()方法是一个非静态方法,只能通过类对象进行访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • getClassLoader() method may throw SecurityException at the time of loading class or interface.

    在加载类或接口时, getClassLoader()方法可能会引发SecurityException

    SecurityException: In this exception, its checkPermission() method does not allow access classloader for the class when the security manager exists.

    SecurityException :在此异常中,当安全管理器存在时,其checkPermission()方法不允许访问该类的类加载器。

Syntax:

句法:

    public ClassLoader getClassLoader();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of this method is ClassLoader, it returns the following values based on the given cases,

此方法的返回类型为ClassLoader ,它根据给定的情况返回以下值:

  • It returns class loader that loads the class denoted by this object.

    它返回类加载器,该加载器加载此对象表示的类。

  • It returns null in case of bootstrap class loader because we don’t need to implement bootstrap class loader.

    如果使用自举类加载器,则返回null ,因为我们无需实现自举类加载器。

Example:

例:

// Java program to demonstrate the example 
// of ClassLoader getClassLoader() method of Class 

public class GetClassLoaderOfClass {
   
   
 public static void main(String[] args) throws Exception {
   
   

  // It returns the Class object attached with the given 
  //classname
  Class cl = Class.forName("GetClassLoaderOfClass");

  // By using getClassLoader() is to load the class
  ClassLoader class_load = cl.getClassLoader();

  // If any ClassLoader associate with the Class
  if (class_load != null) {
   
   

   Class load_class = class_load.getClass();
   System.out.print("Associated Loader Class: ");
   System.out.print(load_class.getName());
  }
  // No Loader associated with the class
  else
   System.out.println("No system loader associated with the class");
 }
}

Output

输出量

Associated Loader Class: jdk.internal.loader.ClassLoaders$AppClassLoader


翻译自: https://www.includehelp.com/java/class-class-getclassloader-method-with-example.aspx

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/146210.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 微信公众平台开发(十) 消息回复总结

    微信公众平台开发(十) 消息回复总结一、简介微信公众平台提供了三种消息回复的格式,即文本回复、音乐回复和图文回复,在这一篇文章中,我们将对这三种消息回复的格式做一下简单讲解,然后封装成函数,以供读者使用。二、思路分析对于每一个POST请

    2022年8月5日
    6
  • 关于component-scan中base-package包含通配符的问题探究

    关于component-scan中base-package包含通配符的问题探究今天在配置Spring的component-scan时,发现了一个有趣的问题。就是在指定base-package时,如果使用了星号通配符*,有时会出现类扫描不到的情况。下面研究一下这个问题。先介绍一下项目结构: 为了演示,我在java文件夹下创建名为controller的包,并在该包下创建了一个名为IndexController的类。如图所示: 先来看正常情况: 在Spring配置…

    2022年6月13日
    86
  • linux oracle修改密码_linux 更改用户密码

    linux oracle修改密码_linux 更改用户密码Linux环境中修改Oracle用户密码第一步:[root@localhost~]#[color=green]su-oracle[/color]第二步:[oracle@localhost~]$[color=green]sqlplus/nolog;[/color]第三步:SQL>…

    2022年7月28日
    29
  • android源码学习-目录「建议收藏」

    android源码学习-目录「建议收藏」一年中感觉进步了不少,现在看android源码已经没有当初那么吃力了。但是和其他开发者的接触过程中,感觉自己对源码的了解还不是很透彻。android不需要所有的源码都去了解,但是几个重要的点的源码还是有必要理解清楚的。自己列了一个表,会去挨个的学习。1.android源码学习-事件分发处理机制2.android源码学习-View绘制流程3.android源码学习-activi…

    2022年6月5日
    23
  • 强制删除文件 强制删除文件夹

    强制删除文件 强制删除文件夹
    在桌面新建一个txt文本打开这个txt文本,输入下面两行内容:
    del/f/s/q//?/%1
    rd /s/q//?/%1
    然后文件->另存为
    重新命名文件名为del.bat,并选择文件类型为“所以文件”,最后保存文件 
    一定要记着文件的位置了把要删除的文件拖到这个批处理del.bat上文件就静悄悄的删除了^-^

    2022年5月30日
    31

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号