Java ObjectStreamFiled compareTo()方法
java.io.ObjectStreamField.compareTo(Object obj) 将此字段与另一个ObjectStreamField进行比较。
1 语法
public int compareTo(Object obj)
2 参数
obj:要比较的对象。
3 返回值
当此对象小于,等于或大于指定的对象时,此方法将返回负整数,零或正整数。
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* java.io.ObjectStreamField.compareTo(Object obj)方法的例子
*/
import java.io.*;
public class Demo {
public static void main(String[] args) {
// create a new object stream class for Integers
ObjectStreamClass osc = ObjectStreamClass.lookupAny(Integer.class);
// get the field value from Integer class
ObjectStreamField field = osc.getField("value");
// create a new object stream class for floats
ObjectStreamClass osc2 = ObjectStreamClass.lookupAny(Float.class);
// get the field value from Integer class
ObjectStreamField field2 = osc.getField("value");
// compare with another field
System.out.println("" + field.compareTo(field2));
}
}
输出结果为:
0