Download Java.io.ObjectStreamField.compareTo(Object obj)

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
JAVA.IO.OBJECTSTREAMFIELD.COMPARETO METHOD
http://www.tutorialspoint.com/java/io/objectstreamfield_compareto.htm
Copyright © tutorialspoint.com
Description
The java.io.ObjectStreamField.compareToObjectobj method compares this field with another
ObjectStreamField. Return -1 if this is smaller, 0 if equal, 1 if greater. Types that are primitives are
"smaller" than object types. If equal, the field names are compared.
Declaration
Following is the declaration for java.io.ObjectStreamField.compareTo method.
public int compareTo(Object obj)
Parameters
obj -- the object to be compared.
Return Value
This method returns a negative integer, zero, or a positive integer as this object is less than, equal
to, or greater than the specified object.
Exception
NA
Example
The following example shows the usage of java.io.ObjectStreamField.compareTo method.
package com.tutorialspoint;
import java.io.*;
public class ObjectStreamFieldDemo {
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));
}
}
Let us compile and run the above program, this will produce the following result:
0
Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js