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