Java ObjectStreamFiled getTypeCode()方法
java.io.ObjectStreamField.getTypeCode() 方法返回字符字段类型的编码。编码如下:
B byte
C char
D double
F float
I int
J long
L class or interface
S short
Z boolean
[ array
1 语法
public char getTypeCode()
2 参数
无
3 返回值
返回可序列化字段的类型代码。
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* java.io.ObjectStreamField.getTypeCode()方法的例子
*/
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");
// get the type code of the field
System.out.println("" + field.getTypeCode());
// create a new object stream class for calendar
ObjectStreamClass osc2 = ObjectStreamClass.lookup(Calendar.class);
// get the field value from Calendar class
ObjectStreamField field2 = osc2.getField("lenient");
// get the type code of the field2
System.out.println("" + field2.getTypeCode());
}
}
输出结果为:
I
Z
热门文章
优秀文章