compareTo(Object): This method is available in the java.io.ObjectStreamField class of Java.
Syntax:
int java.io.ObjectStreamField.compareTo(Object obj)
This method takes one argument. This method compares this field with another ObjectStreamField.
Return-1 if this is smaller, 0 if equal, and 1 if greater. Types that are primitives are "smaller" than object types. If equal, the field names are compared.
Parameters: One parameter is required for this method.
obj: the object to be compared.
Returns: a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Exceptions: NA
Approach
Java
public class ObjectStreamFieldcompareTo {public static void main(String[] args) {ObjectStreamField objectStreamField =new ObjectStreamField("name", String.class);ObjectStreamField obj =new ObjectStreamField("name", String.class);System.out.println(objectStreamField.compareTo(obj));}}
Output:
0
Some more methods of ObjectStreamField
getName(): This method gets the name of this field.
getOffset(): This method returns the offset of the field within instance data.
getType(): This method gets the type of field.
getTypeCode(): This method returns character encoding of the field type.
getTypeString(): This method returns the JVM type signature.
isPrimitive(): This method returns true if this field has a primitive type.
isUnshared(): This method returns a boolean value indicating whether or not the serializable field represented by this ObjectStreamField instance is unshared.
ObjectStreamField(String, Class): This method creates a Serializable field with the specified type.
ObjectStreamField(String, Class, boolean): This method creates an ObjectStreamField representing a serializable field with the given name and type.
toString(): This method returns a string that describes this field.
No comments:
Post a Comment