import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class TestPro {
public TestPro() {
// TODO Auto-generated constructor stub
}
public void setOk1(Object msg) {
System.out.println(msg);
}
public void setOk2(Object msg) {
System.out.println(msg);
}
/**
* @param args
* @throws NoSuchMethodException
* @throws SecurityException
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String [] proName = {"Ok1","Ok2"};//this is the properties
String [] proValue = {"this is the first parameter","this is the second parameter"};//this is the properties value or get the value from all elements;
Object tp = new TestPro();//you can set the class from another method such as setClass(new TestPro())
Class cl = tp.getClass();
Class [] parameters = {Object.class};
Method mt;
for(int i=0;i<proName.length;i++) {
mt = cl.getMethod("set" + proName[i], parameters);
mt.invoke(tp, proValue[i]);
}
}
}
import java.lang.reflect.Method;
public class TestPro {
public TestPro() {
// TODO Auto-generated constructor stub
}
public void setOk1(Object msg) {
System.out.println(msg);
}
public void setOk2(Object msg) {
System.out.println(msg);
}
/**
* @param args
* @throws NoSuchMethodException
* @throws SecurityException
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String [] proName = {"Ok1","Ok2"};//this is the properties
String [] proValue = {"this is the first parameter","this is the second parameter"};//this is the properties value or get the value from all elements;
Object tp = new TestPro();//you can set the class from another method such as setClass(new TestPro())
Class cl = tp.getClass();
Class [] parameters = {Object.class};
Method mt;
for(int i=0;i<proName.length;i++) {
mt = cl.getMethod("set" + proName[i], parameters);
mt.invoke(tp, proValue[i]);
}
}
}