Java Field.getDeclaringClass()

Syntax

Field.getDeclaringClass() has the following syntax.

public Class <?> getDeclaringClass()

Example

In the following code shows how to use Field.getDeclaringClass() method.


/*from   w  ww  .  ja  v a  2  s  . com*/
import java.lang.reflect.Field;

enum Spy {
  BLACK, WHITE
}

public class Main {

  public static void main(String... args)throws Exception {
      Class<?> c = Class.forName("Spy");
      Field[] flds = c.getDeclaredFields();
      for (Field f : flds) {
          System.out.println(f.getDeclaringClass());
        
      }
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang.reflect »




Array
Constructor
Field
Method
Modifier
ParameterizedType
TypeVariable