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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • linux的软连接命令(文件夹建立软连接)

    Linux命令之软连接详解。结合示例详细说明软链接的创建,同时给出如何正确删除一个软链接。

    2022年4月14日
  • Linux重启nodejs

    Linux重启nodejs想要重启nodeserver进入相应的项目执行npmstop发现没用server仍然在,于是要杀掉相应进程1、ps-ef|grepnode查看node对应的pid,然后killpid,再进入对应项目npmstart2、如果以上方法不行可以这样:killnode或者kilallnode

    2022年10月18日
  • 成功鲜有偶然:一览IT名人的教育成长经历

    成功鲜有偶然:一览IT名人的教育成长经历由于篇幅有限,只列举受公共认知度较高的创始人(百度百科对应人物词条被顶超过1000次)国内三强:李彦宏(百度创始人):本科就读于北京大学,硕士就读于布法罗纽约州立大学。曾任Infoseek工程师。马云(阿里巴巴创始人):本科就读于杭州师范学院。马化腾(腾讯创始人):本科就读于深圳大学。大三门户网站:王志东(新浪创始人):本科就读于北京大学,点击科技创始人。丁磊(网易创始人):本科就读于电子科

    2022年8月30日
  • oracle11g的standby性能分析报告statpack安装

    一般常见的分析standbydatabase的性能问题的方法就是通过动态性能视图来判断,从11g开始,随着ActiveDataGuard功能的出现,早期的Statspack工具可以在stand

    2021年12月24日
  • phpstrom 2021激活码(破解版激活)

    phpstrom 2021激活码(破解版激活),https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月16日
  • LSTM时间序列预测及网络层搭建[通俗易懂]

    最近看到一篇博客,是时间预测问题,数据和代码的原地址在这里,https://www.jianshu.com/p/5d6d5aac4dbd下面只是对其复现和思考:首先关于数据预处理的问题,大家可以参考:https://blog.csdn.net/lilong117194/article/details/82911073这里的问题是:给你一个数据集,只有一列数据,这是一个关于时间序列的数据,从…

    2022年4月7日

发表回复

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

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