Java ObjectStreamFiled isUnshared()方法

java.io.ObjectStreamField.isUnshared() 返回布尔值,该布尔值指示此ObjectStreamField实例表示的可序列化字段是否未共享。

1 语法

public boolean isUnshared()

2 参数

3 返回值

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.io.ObjectStreamField.isUnshared()方法的例子
 */
import java.io.*;
import java.util.Calendar;

public class Demo {
    public static void main(String[] args) {

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

        // get the field value from Integer class
        ObjectStreamField field = osc.getField("value");

        // check if field is unshared
        System.out.println("" + field.isUnshared());

        // create a new object stream class for calendar
        ObjectStreamClass osc2 = ObjectStreamClass.lookup(Calendar.class);

        // get the field value from Integer class
        ObjectStreamField field2 = osc2.getField("isSet");

        // check if field is unshared
        System.out.println("" + field2.isUnshared());
    }
}

输出结果为:

false
false

热门文章

优秀文章