Android 中利用反射技术实现加减乘除
2010-08-17 11:00:00 来源:WEB开发网int.class, int.class });
// 调用查找 到的方法执行此方法的处理
Object result = addMethod.invoke(invokeOperation, new Object[] {
new Integer(first), new Integer(second) });
return result.toString();
} else if (oper.equals("-")) {
Method cutMethod = classType.getMethod("cut", new Class[] {
int.class, int.class });
Object result = cutMethod.invoke(invokeOperation, new Object[] {
new Integer(first), new Integer(second) });
return result.toString();
} else if (oper.equals("*")) {
Method rideMethod = classType.getMethod("ride", new Class[] {
int.class, int.class });
Object result = rideMethod.invoke(invokeOperation, new Object[] {
new Integer(first), new Integer(second) });
return result.toString();
} else if (oper.equals("/")) {
Method execMthod = classType.getMethod("Except", new Class[] {
int.class, int.class });
Object result = execMthod.invoke(invokeOperation, new Object[] {
new Integer(first), new Integer(second) });
return result.toString();
}
return "";
}
}
Tip:在JAVA中可以通过main 函数打印,在Android 好像调用会出错。via:http://www.cnblogs.com/TerryBlog/archive/2010/08/17/1801559.html
更多精彩
赞助商链接