ObjectStreamField(String, Class, boolean): This method is available in the java.io.ObjectStreamField class of Java.
Syntax:
java.io.ObjectStreamField.ObjectStreamField(String name, Class<?> type, boolean unshared)
This method takes three arguments. This method creates an ObjectStreamField representing a serializable field with the given name and type.
If unshared is false, values of the represented field are serialized and deserialized in the default manner--if the field is non-primitive, object values are serialized and deserialized as they had been written and read by calls to writeObject and read the object.
If unshared is true, values of the represented field are serialized and deserialized as if they had been written and read by calls to writeUnshared and readUnshared.
Parameters: Three parameters are required for this method.
name: field name.
type: field type.
unshared: if false, write/read field values in the same manner as writeObject/readObject; if true, write/read in the same manner as writeUnshared/readUnshared.
Exceptions: NA
Approach
Java
import java.io.ObjectStreamField;public class ObjectStreamFieldObjectStreamField2 {public static void main(String[] args) {ObjectStreamField objectStreamField =new ObjectStreamField("name", String.class, true);System.out.println(objectStreamField);}}
Output:
Ljava/lang/String; name
Some more methods of ObjectStreamField
compareTo(Object): This method compares this field with another 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.
toString(): This method returns a string that describes this field.
No comments:
Post a Comment