Search This Blog

Java Reflection for Fields

1. Overview

A field may be either of primitive or reference type. There are eight primitive types: boolean, byte, short, int, long, char, float, and double. A reference type is anything that is a direct or indirect subclass of java.lang.Object including interfaces, arrays, and enumerated types.

Reflection API provides several methods to analyze Class fields and modify their values at runtime, in this guide, we will look into some of the commonly used reflection functions for methods.

2.2 Get Public Field

Reflection API also provides a method to get a specific public field of a class through getField()method. This method looks for the field in the specified class reference and then in the super interfaces and then in the superclasses.