Java.io.ObjectStreamClass.lookupAny() Method

Advertisements


Description

The java.io.ObjectStreamClass.lookupAny(Class<?> cl) method returns the descriptor for any class, regardless of whether it implements Serializable.

Declaration

Following is the declaration for java.io.ObjectStreamClass.lookupAny() method

public static ObjectStreamClass lookupAny(Class<?> cl)

Parameters

  • cl -- class for which to get the descriptor

Return Value

This method returns the class descriptor for the specified class

Exception

  • NA

Example

The following example shows the usage of java.io.ObjectStreamClass.lookupAny() method.

package com.tutorialspoint;

import java.io.*;
import java.util.Calendar;

public class ObjectStreamClassDemo {

   public static void main(String[] args) {

      // create a new object stream class for Integers
      ObjectStreamClass osc = ObjectStreamClass.lookupAny(Integer.class);

      // get the name for Integers
      System.out.println("" + osc.getName());

      // create a new object stream class for Thread, which is not serializable
      ObjectStreamClass osc2 = ObjectStreamClass.lookupAny(Thread.class);

      // get the name for Calendar
      System.out.println("" + osc2.getName());
   }
}

Let us compile and run the above program, this will produce the following result:

java.lang.Integer
java.lang.Thread



Advertisements
Advertisements