Home » Java programming language

Java ObjectInputStream resolveClass() Method with Example

ObjectInputStream Class resolveClass() method: Here, we are going to learn about the resolveClass() method of ObjectInputStream Class with its syntax and example.
Submitted by Preeti Jain, on April 05, 2020

ObjectInputStream Class resolveClass() method

  • resolveClass() method is available in java.io package.
  • resolveClass() method is used to load the local class that is similar to the given ObjectStreamClass descriptor.
  • 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() method may throw an exception at the time of resolving class.
    • ClassNotFoundException: This exception may throw when the serialized object Class could not exist.
    • IOException: This exception may throw when getting any input/output error while performing.

Syntax:

    protected Class resolveClass(ObjectStreamClass description);

Parameter(s):

  • ObjectStreamClass description – represents the instance of this ObjectStreamClass.

Return value:

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

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


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.