Java Reflection - Java Constructor .getDeclaringClass ()








Syntax

Constructor.getDeclaringClass() has the following syntax.

public Class <T> getDeclaringClass()

Example

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

import java.lang.reflect.Constructor;
// w ww .ja  va  2s  . c o m
public class Main {
  public static void main(String[] args) throws ClassNotFoundException {
    Class c = Class.forName("java.lang.String");

    Constructor[] constructors = c.getDeclaredConstructors();
    for (int i = 0; i < constructors.length; i++) {
      System.out.println(constructors[i].getDeclaringClass());
    }

  }
}

The code above generates the following result.