Java ObjectStreamFiled toString()方法

java.io.ObjectStreamField.toString() 它返回描述此字段的字符串

1 语法

public String toString()

2 参数

3 返回值

返回对象的字符串表示形式。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.io.ObjectStreamField.toString()方法的例子
 */
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");

        // print field as a string
        System.out.println("" + field.toString());

        // 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");

        // print field as a string
        System.out.println("" + field2.toString());
    }
}

输出结果为:

I value
[Z isSet

热门文章

优秀文章