Java.io.ObjectStreamField.toString() Method

Advertisements


Description

The java.io.ObjectStreamField.toString() method returns a string that describes this field.

Declaration

Following is the declaration for java.io.ObjectStreamField.toString() method

public String toString()

Parameters

  • NA

Return Value

This method returns a string representation of the object.

Exception

  • NA

Example

The following example shows the usage of java.io.ObjectStreamField.toString() method.

package com.tutorialspoint;

import java.io.*;
import java.util.Calendar;

public class ObjectStreamFieldDemo {

   public static void main(String[] args) {

      // create a new object stream class for Integers
      ObjectStreamClass osc = ObjectStreamClass.lookup(Integer.class);

      // get the field value from Integer class
      ObjectStreamField field = osc.getField("value");

      // print field as a string
      System.out.println("" + field.toString());

      // create a new object stream class for calendar
      ObjectStreamClass osc2 = ObjectStreamClass.lookup(Calendar.class);

      // get the field value from Integer class
      ObjectStreamField field2 = osc2.getField("isSet");

      // print field as a string
      System.out.println("" + field2.toString());

   }
}

Let us compile and run the above program, this will produce the following result:

I value
[Z isSet



Advertisements
Advertisements