Home » Java programming language

Java ObjectStreamClass getFields() Method with Example

ObjectStreamClass Class getFields() method: Here, we are going to learn about the getFields() method of ObjectStreamClass Class with its syntax and example.
Submitted by Preeti Jain, on April 12, 2020

ObjectStreamClass Class getFields() method

  • getFields() method is available in java.io package.
  • getFields() method is used to return all the named fields of this ObjectStreamClass.
  • getFields() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • getFields() method does not throw an exception at the time of returning named fields.

Syntax:

    public ObjectStreamField[] getFields();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is ObjectStreamField [], it returns an array of the named ObjectStreamField object that contain all the fields when exists.

Example:

// Java program to demonstrate the example 
// of ObjectStreamField[] getFields()
// method of ObjectStreamClass

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

public class GetFields {
 public static void main(String[] args) {
  // Instantiates ObjectStreamClass for 
  // and Calendar
  ObjectStreamClass o_stm = ObjectStreamClass.lookup(Calendar.class);

  // By using getFields() method is to return
  // the fields of this class
  ObjectStreamField[] osf_stm = o_stm.getFields();

  for (int i = 0; i < osf_stm.length; ++i)
   System.out.println("o_stm.getFields(): " + osf_stm[i]);
 }
}

Output

o_stm.getFields(): Z areFieldsSet
o_stm.getFields(): I firstDayOfWeek
o_stm.getFields(): Z isTimeSet
o_stm.getFields(): Z lenient
o_stm.getFields(): I minimalDaysInFirstWeek
o_stm.getFields(): I nextStamp
o_stm.getFields(): I serialVersionOnStream
o_stm.getFields(): J time
o_stm.getFields(): [I fields
o_stm.getFields(): [Z isSet
o_stm.getFields(): Ljava/util/TimeZone; zone


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.