Get constructors

ReturnMethodSummary
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)
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.