MyObject destObject = new MyObject();
Class<? extends Object> piClass = destObject.getClass();
Method[] arrayPiMethod = piClass.getDeclaredMethods();
// ================= setter 실행.
for(Method methodPi : arrayPiMethod) {
String methodName = methodPi.getName();
try {
if(methodName.startsWith("set")) {
Class[] paramObj = methodPi.getParameterTypes();
Object callParameter = null;
If(paramObj[0] == String.class) {
callParameter = new String("test");
} else If(paramObj[0] == int.class) {
callParameter = new Integer(1);
}
methodPi.invoke(destObject, new Object[] { callParameter } );
}
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
}
// ================= getter 실행.
for(Method methodPi : arrayPiMethod){
if(methodPi.getName().startsWith("get")) {
try {
Object obj = methodPi.invoke(object, new Object[]{});
System.out.println("return value : " + obj);
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
}
}
'프로그래밍 > Java' 카테고리의 다른 글
[android] c2dm 보낼때 exception 발생. (0) | 2012.02.20 |
---|---|
[이클립스] jad clipse 플러그인. (0) | 2011.10.26 |
[spring] static 변수에 autowired 설정하기. (0) | 2011.09.20 |
String -> Json (0) | 2011.09.19 |
http request post data 읽기. (0) | 2011.09.19 |