Java ClassLoader resolveClass()方法与示例

ClassLoader类resolveClass()方法 (ClassLoader Class resolveClass() method)

  • resolveClass() method is available in java.lang package.

    resolveClass()方法在java.lang包中可用。

  • resolveClass() method is used to link the specified class let suppose when class A has been linked already then in that case this method simply returns.

    假设已经链接了类A时,可使用resolveClass()方法链接指定的类,那么在这种情况下,此方法只是返回。

  • resolveClass() 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.

    resolveClass()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • resolveClass() method may throw an exception at the time of linking class.

    resolveClass()方法在链接类时可能会引发异常。

    NullPointerException: In this exception when the given class is null.

    NullPointerException :在给定的类为null的情况下,此异常。

Syntax:

句法:

    protected void resolveClass(Class cl_name);

Parameter(s):

参数:

  • Class cl_name – represents the name of the class to link.

    类cl_name –表示要链接的类的名称。

Return value:

返回值:

The return type of this method is void, it returns nothing.

此方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example 
// of void resolveClass(Class cl_name) method of ClassLoader 

public class ResolveClass extends ClassLoader {
 ResolveClass(Class cl1) {
  // By using super keyword to call parent class
  // Constructor
  super.resolveClass(cl1);

  // Display Resolve Class Name
  System.out.println("Class Name: " + cl1.getSimpleName());
 }

 public static void main(String[] args) throws Exception {
  // We are parsing Class to ClassLoader constructor
  Class cl = Class.forName("java.lang.String");

  // Calling ResolveClass Constructor
  ResolveClass rc = new ResolveClass(cl);
 }
}

Output

输出量

Class Name: String


翻译自: https://www.includehelp.com/java/classloader-resolveclass-method-with-example.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值