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


相关推荐

  • python 存储bmp格式图片[通俗易懂]

    python 存储bmp格式图片[通俗易懂]importnumpyasnpfromPILimportImage#读入数据arr,此处为手动设置arr=np.array([[0,0,0,0,0],[0,0,0,0,0],[1,1,1,1,1],[1,1,1,1,1],[0,0,0,0,0]])#将元素类型更改为’uint8’arr=np.array(arr,dtype=’uint8′)arr=Image.froma

    2025年6月7日
    0
  • 数列极限定义详解「建议收藏」

    数列极限定义详解「建议收藏」数列极限的定义个人感觉不太好理解,我看了两天的教程才彻底明白数列极限的定义。在一般的教材里数列极限的定义为这说的比较抽象,我半天都理解不了N是怎么来的,n与N有什么区别,为什么要用去减a,这里我对自己的疑问做了个总结。首先是为什么要用去减a,两个数之间的接近程度可以用两个之差的绝对值来度量,差值越小,两个数就越接近(说法来源于《高等数学》同济大学)。两个数的接近程度小于任给的正数​…

    2022年4月29日
    34
  • C#引用C++代码

    现在在Windows下的应用程序开发,VS.Net占据了绝大多数的份额。因此很多以前搞VC++开发的人都转向用更强大的VS.Net。在这种情况下,有很多开发人员就面临了如何在C#中使用C++开发好的类

    2021年12月22日
    42
  • Mysql覆盖索引_mysql索引长度限制

    Mysql覆盖索引_mysql索引长度限制如果一个索引包含(或覆盖)所有需要查询的字段的值,称为‘覆盖索引’。即只需扫描索引而无须回表。只扫描索引而无需回表的优点:    1.索引条目通常远小于数据行大小,只需要读取索引,则mysql会极大地减少数据访问量。    2.因为索引是按照列值顺序存储的,所以对于IO密集的范围查找会比随机从磁盘读取每一行数据的IO少很多。    3.一些存储引擎如myisam在内存中只缓存索引,数据则依赖于操作…

    2022年8月30日
    0
  • 什么是td-scdma_TR缩写

    什么是td-scdma_TR缩写3GPP 3rd Generation PartnershipProject 第三代移动通信伙伴组织AAAAntenna Array 天线阵AALATM Adaptation Layer ATM适配层AAL2ATM Adaptati

    2022年9月26日
    0
  • 背包问题九讲笔记_01背包[通俗易懂]

    背包问题九讲笔记_01背包[通俗易懂]摘自TianyiCui童鞋的《背包问题九讲》,稍作修改,方便理解。01背包问题描述已知:有一个容量为V的背包和N件物品,第i件物品的重量是weight[i],收益是cost[i]。限制:每种物品只有一件,可以选择放或者不放问题:在不超过背包容量的情况下,最多能获得多少价值或收益相似问题:在恰好装满背包的情况下,最多能获得多少价值或收益这里,我们先讨论在不超过背包容量的情况

    2022年7月12日
    22

发表回复

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

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