Mega Code Archive

 
Categories / Java / Reflection
 

Get all construtors from a class

import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; public class Main{   public static void main(String args[]) throws Exception {     Class c = Class.forName("MyClass");     System.out.println("Constructors:");     Constructor constructors[] = c.getDeclaredConstructors();     for (Constructor cons : constructors)       System.out.println(" " + cons);   } } class MyClass {   private int count;   MyClass(int c) {     count = c;   }   MyClass() {     count = 0;   }   void setCount(int c) {     count = c;   }   int getCount() {     return count;   }   void showcount() {     System.out.println("count is " + count);   } }