ObjectStreamField getTypeCode() in Java

getTypeCode(): This method is available in the java.io.ObjectStreamField class of Java.

Syntax:

char java.io.ObjectStreamField.getTypeCode()

This method returns character encoding of the field type.

The encoding is as follows: 

 B            byte

 C            char

 D            double

 F            float

 I            int

 J            long

 L            class or interface

 S            short

 Z            boolean

 [            array

Parameters: NA

Returns: the type code of the serializable field.

Exceptions: NA

Approach

Java

import java.io.ObjectStreamField;

public class ObjectStreamFieldgetTypeCode {
    public static void main(String[] args) {

        ObjectStreamField objectStreamField =
new ObjectStreamField("name", String.class);

        System.out.println(objectStreamField.getTypeCode());
    }
}

Output:

L


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.

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