Java ObjectInputStream resolveClass()方法与示例

本文详细介绍了Java IO包中ObjectInputStream类的resolveClass()方法,该方法用于加载与给定ObjectStreamClass描述符相似的本地类。文章解释了方法的使用场景、参数和返回值,并提供了一个示例程序,展示了如何使用此方法。
摘要由CSDN通过智能技术生成

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

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

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

  • resolveClass() method is used to load the local class that is similar to the given ObjectStreamClass descriptor.

    resolveClass()方法用于加载与给定的ObjectStreamClass描述符相似的本地类。

  • 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 resolving class.

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

    • ClassNotFoundException: This exception may throw when the serialized object Class could not exist.ClassNotFoundException :当序列化的对象Class不存在时,可能引发此异常。
    • IOException: This exception may throw when getting any input/output error while performing.IOException :在执行过程中遇到任何输入/输出错误时,可能引发此异常。

Syntax:

句法:

    protected Class resolveClass(ObjectStreamClass description);

Parameter(s):

参数:

  • ObjectStreamClass description – represents the instance of this ObjectStreamClass.

    ObjectStreamClass描述 –表示此ObjectStreamClass的实例。

Return value:

返回值:

The return type of the method is Class, it returns Class object equivalent to the given Description.

方法的返回类型为Class ,它返回与给定Description等效的Class对象。

Example:

例:

// Java program to demonstrate the example 
// of Class resolveClass(ObjectStreamClass description) 
// method of ObjectInputStream

public class GetSignersOfClass {
 public static void main(String[] args) throws Exception {
  // Creating an instance of String
  String str = new String();

  // It returns the Class object represented by the String class
  //object
  Class cl = str.getClass();

  // By using getSigners() method is to get the signers of the Class
  Object[] o = cl.getSigners();
  System.out.println(cl.getName() + " " + "Signers: " + o);
 }
}

Output

输出量

java.lang.String Signers: null


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值