Get Class Description Using Methods of java.lang.Class


/*Program to get details of a class given on command line argument*/
import java.lang.reflect.*;
class Descriptor
{
public static void main(String args[])
{
try
{
Class c = Class.forName(args[0]);
Field f[] = c.getDeclaredFields();
System.out.println("Various Fields of class are : ");
for(int i = 0;i<f.length;i++)
{
System.out.println(f[i]);
}
Constructor ctr[] = c.getDeclaredConstructors();
System.out.println("Various Constructors of class are : ");
for(int i = 0;i<ctr.length;i++)
{
System.out.println(ctr[i]);
}
Method m[] = c.getDeclaredMethods();
System.out.println("Various methods of class are : ");
for(int i=0;i<m.length;i++)
{
System.out.println(m[i]);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}


0 Comments:

Post a Comment