例子
以下示例显示java.io.ObjectStreamClass.forClass()方法的用法。
package com.jc2182;
import java.io.*;
public class ObjectStreamClassDemo {
public static void main(String[] args) {
// create a new object stream class for Integers
ObjectStreamClass osc = ObjectStreamClass.lookup(Integer.class);
// get the Class instance for osc
System.out.println("" + osc.forClass());
// create a new object stream class for Strings
ObjectStreamClass osc2 = ObjectStreamClass.lookup(String.class);
// get the Class instance for osc
System.out.println("" + osc2.forClass());
}
}
让我们编译并运行以上程序,这将产生以下结果-
class java.lang.Integer
class java.lang.String