Tuesday, August 25, 2009
Reflection Technique in Java
This is an example to call an method using Reflection Technique.
Class cls = obj.getClass();
Class[] par = new Class[1];
par[0] = String.class
Method m = null;
try{
m = cls.getMethod("showMessage",par)
}catch(Exception ex){
}
Object[] pa = new Object[1];
pa[0] = "This is beginning";
try{
String output = (String)m.invoke(obj,pa);
System.out.println(output);
}catch(Exception o){
}
Class cls = obj.getClass();
Class[] par = new Class[1];
par[0] = String.class
Method m = null;
try{
m = cls.getMethod("showMessage",par)
}catch(Exception ex){
}
Object[] pa = new Object[1];
pa[0] = "This is beginning";
try{
String output = (String)m.invoke(obj,pa);
System.out.println(output);
}catch(Exception o){
}
Saturday, August 1, 2009
Subscribe to:
Posts (Atom)