Get constructors

Constructor<T> getConstructor(Class<?>... parameterTypes)
Returns a Constructor object that reflects the specified public constructor of the class represented by this Class object.
Constructor<?>[] getConstructors()
Returns an array containing Constructor objects reflecting all the public constructors of the class represented by this Class object.

  import java.lang.reflect.Constructor;

public class Main {
  public static void main(String args[]) {

    System.out.println("Constructors:");
    Constructor constructors[] = new String().getClass().getConstructors();
    for (int i = 0; i < constructors.length; i++) {
      System.out.println(" " + constructors[i]);
    }

  }
}
  

The output:


Constructors:
 public java.lang.String()
 public java.lang.String(java.lang.String)
 public java.lang.String(char[])
 public java.lang.String(char[],int,int)
 public java.lang.String(int[],int,int)
 public java.lang.String(byte[],int,int,int)
 public java.lang.String(byte[],int)
 public java.lang.String(java.lang.StringBuilder)
 public java.lang.String(byte[],int,int,java.lang.String) throws java.io.UnsupportedEncodingException
 public java.lang.String(byte[],int,int,java.nio.charset.Charset)
 public java.lang.String(byte[],java.lang.String) throws java.io.UnsupportedEncodingException
 public java.lang.String(byte[],java.nio.charset.Charset)
 public java.lang.String(byte[],int,int)
 public java.lang.String(byte[])
 public java.lang.String(java.lang.StringBuffer)
Home 
  Java Book 
    Reflection  

Class:
  1. Class Reflection
  2. Get Class from class name
  3. Get class name
  4. Get constructors
  5. Get fields in this class
  6. Get Modifiers
  7. Get package
  8. Check class type
  9. Create new instance
  10. Convert class to string