例子
以下示例显示java.io.ObjectStreamClass.lookupAny()方法的用法。
package com.jc2182;
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());
}
}
让我们编译并运行以上程序,这将产生以下结果-
java.lang.Integer
java.lang.Thread