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


相关推荐

  • P3381 【模板】最小费用最大流

    P3381 【模板】最小费用最大流

    2021年5月28日
    106
  • 学会使用getopt函数[通俗易懂]

    学会使用getopt函数[通俗易懂]简介getopt函数是命令行参数解析函数,在平时阅读源码的时候经常遇到,很有必要对其总结一下,做个记录!命令行参数各组成部分的名称先来了解下命令行参数各组成部分的名称。直接上图:非常清楚,命令行参数由Commandname,Option,Optionargument以及Operands组成。Commandname不用多说,就是程序的名称。操作对象Operands又…

    2022年6月9日
    48
  • python3 gil锁_python 全局锁

    python3 gil锁_python 全局锁前言python的使用者都知道Cpython解释器有一个弊端,真正执行时同一时间只会有一个线程执行,这是由于设计者当初设计的一个缺陷,里面有个叫GIL锁的,但他到底是什么?我们只知道因为他导致pyt

    2022年7月30日
    4
  • 利用ItextPdf、core-renderer-R8 来生成PDF「建议收藏」

    利用ItextPdf、core-renderer-R8 来生成PDF

    2022年1月29日
    45
  • oracle中怎么跳出循环,oracle 跳出循环方法

    oracle中怎么跳出循环,oracle 跳出循环方法记录exit和return的用法1.exit用来跳出循环Oracle代码:declareV_KBPvarchar2(10);beginloopIFV_KBPISNULLTHENEXIT;ENDIF;endloop;dbms_output.put_line(‘退出’);end;exit跳出循环(示例中跳到第8行)后,仍然输出“退出”2.return跳记录…

    2022年6月4日
    37
  • C语言-判断回文字符串(二)

    C语言-判断回文字符串(二)7-2 判断回文字符串 (15分)输入一个字符串,判断该字符串是否为回文。回文就是字符串中心对称,从左向右读和从右向左读的内容是一样的。输入格式:输入在一行中给出一个不超过80个字符长度的、以回车结束的非空字符串。输出格式:输出在第1行中输出字符串。如果它是回文字符串,在第2行中输出Yes,否则输出No。输入样例1:level输出样例1:levelYe…

    2022年5月30日
    48

发表回复

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

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