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)
上一篇 2022年5月15日 下午5:40
下一篇 2022年5月15日 下午5:40


相关推荐

  • SLAM技术课程总结「建议收藏」

    SLAM技术课程总结「建议收藏」这学期SLAM技术课程遇到最多的问题,或者说困难更合适,其实和学生无关。专业培养方案中,SLAM技术是双语课程,但此课对数学要求极高,通常应用型本科院校学生的数学基础并不具备直接学习此课程的条件; 操作环境要求学生需在Linux系统下完成,虽然现在有云端实践平台,但掌握基本的Linux命令依然是必不可少的基础,对于机器人工程专业学生而言,课程体系忽略了这块训练,使此课孤立于课程体系中,无法和现有培养方案的其他课程形成良性互动; 编程要求C++11,当然能够掌握14以上更好,而之前的课程多侧重于C和

    2022年10月1日
    5
  • eruda.js 移动端调试神器使用教程(eruda)

    eruda.js 移动端调试神器使用教程(eruda)在日常的移动端开发时,一般都是试用chrome浏览器的移动端模式进行开发和调试,只有在chrome调试完成,没有问题了才会上到真机测试,移动端开发的一大问题就在于此,各种品牌各种型号手机,手机中各种类型的浏览器APP…还好移动端的相对一致点,但是往往都会有一些各种各样的坑,这时候就蛋疼了,明明chrome调试工具中是正常的,一到某个浏览器中就炸了,怎么办,又无法像在chrome中使用调试工具进行调试,只能通过alert()弹窗来调试,有什么办法可以像PC上那样清晰,可视化的调试呢?使用示例://#

    2025年7月23日
    4
  • FlashFXP 3.6 Final(正式版)注册码

    FlashFXP 3.6 Final(正式版)注册码昨天登陆FTP提示是否要升级,也没有注意点了下同意,结果升级后是最新英文版本的,把原来的资料也给丢了,忙了半天一看原来的注册码已经不好使用,在网上搜索下,找到一个可以使用的注册码和大家分享下:———————————————————FLASHFXPxgA9UrTnxgAAAAC7W5MNJwTnsl73n0Vuu1AePJgEAG41mgSvHSiDWi1Kg8B5xJNCCCAVCMr9R

    2022年7月26日
    20
  • 清除SVN未版控文件

    清除SVN未版控文件

    2021年10月20日
    46
  • 企业微信机器人定时发送信息

    企业微信机器人定时发送信息企业微信可以配置机器人,提升办公效率,还能实现一键群发和定时发送等功能。

    2022年6月16日
    44
  • input file 只读实现

    input file 只读实现//禁止粘贴,禁止直接写路径  

    2022年7月25日
    14

发表回复

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

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