Example usage for java.lang.reflect Constructor getName

List of usage examples for java.lang.reflect Constructor getName

Introduction

In this page you can find the example usage for java.lang.reflect Constructor getName.

Prototype

@Override
public String getName() 

Source Link

Document

Returns the name of this constructor, as a string.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Constructor[] constructors = ArrayList.class.getDeclaredConstructors();

    for (int i = 0; i < constructors.length; i++) {
        Constructor c = constructors[i];
        System.out.println(c.getName());
    }// w  w w.  jav  a 2s . co m
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Class clazz = String.class;

    Constructor[] constructors = clazz.getDeclaredConstructors();
    for (Constructor constructor : constructors) {
        String name = constructor.getName();
        System.out.println("Constructor name= " + name);

        Class[] paramterTypes = constructor.getParameterTypes();
        for (Class c : paramterTypes) {
            System.out.println("Param type name = " + c.getName());
        }/*  ww w.  j a  v a 2  s.c  o  m*/
    }

    Constructor constructor = String.class.getConstructor(new Class[] { String.class });
    System.out.println("Constructor     = " + constructor.getName());
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File f = new File("c:/mysql-connector-java-5.1.18-bin.jar");
    URLClassLoader urlCl = new URLClassLoader(new URL[] { f.toURL() }, System.class.getClassLoader());

    Class mySqlDriver = urlCl.loadClass("com.mysql.jdbc.Driver");
    System.out.println(mySqlDriver.newInstance());
    System.out.println("Is this interface? = " + mySqlDriver.isInterface());

    Class interfaces[] = mySqlDriver.getInterfaces();
    int i = 1;//w  w  w .  j a v  a2 s.c  om
    for (Class _interface : interfaces) {
        System.out.println("Implemented Interface Name " + (i++) + " = " + _interface.getName());
    }

    Constructor constructors[] = mySqlDriver.getConstructors();
    for (Constructor constructor : constructors) {
        System.out.println("Constructor Name = " + constructor.getName());
        System.out.println("Is Constructor Accessible? = " + constructor.isAccessible());
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Constructor[] constructors = String.class.getDeclaredConstructors();
    for (int i = 0; i < constructors.length; i++) {
        Constructor c = constructors[i];
        Class[] paramTypes = c.getParameterTypes();
        String name = c.getName();
        System.out.print(Modifier.toString(c.getModifiers()));
        System.out.print(" " + name + "(");
        for (int j = 0; j < paramTypes.length; j++) {
            if (j > 0)
                System.out.print(", ");
            System.out.print(paramTypes[j].getCanonicalName());
        }/*from  ww  w .ja v  a2s . co  m*/
        System.out.println(");");
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Class cls = java.lang.String.class;
    Method method = cls.getMethods()[0];
    Field field = cls.getFields()[0];
    Constructor constructor = cls.getConstructors()[0];
    String name;/*from  w  w w.  j  a v a  2  s .  c  o m*/

    name = cls.getName();
    System.out.println(name);
    name = cls.getName() + "." + field.getName();
    System.out.println(name);
    name = constructor.getName();
    System.out.println(name);
    name = cls.getName() + "." + method.getName();
    System.out.println(name);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Class cls = java.lang.String.class;
    Method method = cls.getMethods()[0];
    Field field = cls.getFields()[0];
    Constructor constructor = cls.getConstructors()[0];
    String name;/*www.jav a  2  s  .co  m*/

    name = cls.getName().substring(cls.getPackage().getName().length() + 1);
    System.out.println(name);
    name = field.getName();
    System.out.println(name);
    name = constructor.getName().substring(cls.getPackage().getName().length() + 1);
    System.out.println(name);
    name = method.getName();
    System.out.println(name);

}

From source file:ReflectionTest.java

public static void printConstructors(Class cl) {
    Constructor[] constructors = cl.getDeclaredConstructors();

    for (int i = 0; i < constructors.length; i++) {
        Constructor c = constructors[i];
        Class[] paramTypes = c.getParameterTypes();
        String name = c.getName();
        System.out.print(Modifier.toString(c.getModifiers()));
        System.out.print(" " + name + "(");
        for (int j = 0; j < paramTypes.length; j++) {
            if (j > 0)
                System.out.print(", ");
            System.out.print(paramTypes[j].getName());
        }/*from w  ww . j  a va2 s  .  c o  m*/
        System.out.println(");");
    }
}

From source file:ReflectionTest.java

/**
 * Prints all constructors of a class//  w w  w. ja v a2s  . c o  m
 * @param cl a class
 */
public static void printConstructors(Class cl) {
    Constructor[] constructors = cl.getDeclaredConstructors();

    for (Constructor c : constructors) {
        String name = c.getName();
        System.out.print("   ");
        String modifiers = Modifier.toString(c.getModifiers());
        if (modifiers.length() > 0)
            System.out.print(modifiers + " ");
        System.out.print(name + "(");

        // print parameter types
        Class[] paramTypes = c.getParameterTypes();
        for (int j = 0; j < paramTypes.length; j++) {
            if (j > 0)
                System.out.print(", ");
            System.out.print(paramTypes[j].getName());
        }
        System.out.println(");");
    }
}

From source file:Main.java

public static String ctorToString(Constructor constructor) {
    Class[] params = constructor.getParameterTypes();
    StringBuffer sb = new StringBuffer(constructor.getName());
    sb.append("(");
    for (int i = 0; i < params.length; i++) {
        String s = params[i].getName();
        sb.append(s);//from  ww  w . ja  va 2  s  .  c o m
        if (i < params.length - 1) {
            sb.append(", ");
        }
    }
    sb.append(")");
    return sb.toString();
}

From source file:MyClass.java

public static ArrayList<String> getConstructorsDesciption(Constructor[] constructors) {
    ArrayList<String> constructorList = new ArrayList<>();
    for (Constructor constructor : constructors) {
        String modifiers = getModifiers(constructor);

        String constructorName = constructor.getName();

        constructorList.add(modifiers + "  " + constructorName + "(" + getParameters(constructor) + ") "
                + getExceptionList(constructor));
    }/* w  w  w .  j a va2s  .com*/
    return constructorList;
}