Reflection Program in java
Source code::
import java.lang.reflect.*;
public class Reflection
{
public static void main(String args[])
{
try
{
System.out.println("enter the method name");
Class c = Class.forName(args[0]);
Method[] m = c.getDeclaredMethods();
for(int i=0;i<=m.length;i++)
{
System.out.println(m[i]);
}
System.out.println("enter the name of class");
Constructor[] con = c.getDeclaredConstructors();
for(int i=0;i<con.length;i++)
{
System.out.println(con[i]);
}
System.out.println("enter the name of class");
Field[] f = c.getDeclaredFields();
for(int i=0;i<f.length;i++)
{
System.out.println(f[i]);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
import java.lang.reflect.*;
public class Reflection
{
public static void main(String args[])
{
try
{
System.out.println("enter the method name");
Class c = Class.forName(args[0]);
Method[] m = c.getDeclaredMethods();
for(int i=0;i<=m.length;i++)
{
System.out.println(m[i]);
}
System.out.println("enter the name of class");
Constructor[] con = c.getDeclaredConstructors();
for(int i=0;i<con.length;i++)
{
System.out.println(con[i]);
}
System.out.println("enter the name of class");
Field[] f = c.getDeclaredFields();
for(int i=0;i<f.length;i++)
{
System.out.println(f[i]);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
// you can able to find the methods ,constructors,and fields of your desirable class.
//for more program mail me on - er.gauravsrivastava.cse@gmail.com
https://www.facebook.com/pages/Get-It-Here/960012334020603?pnref=story
ReplyDelete