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


相关推荐

  • 软考之计算机病毒「建议收藏」

    软考之计算机病毒「建议收藏」在复习软考的时候,发现计算机病毒方面的知识在软件设计师教程这本书上没怎么介绍,但是这部分的内容还常考。所以把计算机病毒方面的知识总结了一下,下面我就来一一介绍一下这些病毒。 1、引导型病毒:引导型病毒隐藏在磁盘内,在系统文件启动前已经驻留在内存中。主要感染磁盘的引导区,影响软盘或硬盘的引导扇区 2、文件型病毒:通常感染执行文件(包括exe和com文件等)但也有些会感染其他可执行

    2022年6月5日
    36
  • NFV介绍_NFV技术

    NFV介绍_NFV技术转发自:https://zhuanlan.zhihu.com/p/26259440NFV全称是NetworkFunctionVirtualization。这又是一个与网络相关的故事。先来看看NFV的前世今生吧。在NFV之前,NF(NetworkFunction)是一直存在的,网络中,NF可以看成一个个独立的网元,实现着各自的功能。NF以固定的方式连接起来,统一提供的网络功能和服务。随便在网…

    2025年10月16日
    5
  • 对Java线程池ThreadPoolExecutor的理解分析

    对Java线程池ThreadPoolExecutor的理解分析主要放在后面做总结(重点查看下:http://www.ideabuffer.cn/,刚发现一个宝藏)参考文献:1.http://www.ideabuffer.cn/2017/04/04/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3Java%E7%BA%BF%E7%A8%8B%E6%B1%A0%EF%BC%9AThreadPoolExecutor/2.https://tech.meituan.com/2020/04/02/java-pooling-pratice-i

    2022年7月12日
    20
  • 总体方差和样本方差

    总体方差和样本方差讨论了总体方差和样本方差的区别

    2026年3月18日
    1
  • uniqueidentifier类型_unique用法及搭配

    uniqueidentifier类型_unique用法及搭配uniqueidentifier  全局唯一标识符 (GUID)。    注释  uniqueidentifier 数据类型的列或局部变量可用两种方法初始化为一个值:     使用 NEWID 函数。    将字符串常量转换为如下形式(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,其中每个 x 是 0-9

    2025年10月6日
    5
  • 二进制异或逻辑运算的规则是_异或运算相同为1不同为0

    二进制异或逻辑运算的规则是_异或运算相同为1不同为0用^代表事件相反一、与有0出0;全1出1ABF=AB000010100111二、或有1出1;全0出0ABF=A+B000011101111三、非有1出0;有0出1。AF=^A01

    2022年10月12日
    4

发表回复

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

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