向经常用反射的人求个通用的函数 最近程序里频繁用到反射,我想向大家求个通用的几个函数类1.通过名字动态调用对象的字段,并获取其值2.通过名字动态获取对象的方法,并调用,返回其结果(包括函数和方法) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 小弟我自己写了一个很笨拙的函数 望大家指点改良下class Invoke{public static void reflectCall(Object obj,String methodName,Class[] types,Object[] objs) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { Method callMethod=obj.getClass().getMethod(methodName, types); callMethod.invoke(obj, objs); } public static void main(String args[]) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { test temp=new test(); reflectCall(temp,"print", new Class[] {String.class},new Object[]{"1"}); } }class test{ public void print(String i) { System.out.println("atswtewtw"); } public void print(int i) { System.out.println(i); }} java String处理问题 到底这是为什么呢? 用xml文件记录log4j生成的日志信息 初学,帮忙看个简单的程序啊~~~~ 靠!如此简单的程序,却找不到错误,帮我。。。。 请教一个简单问题:如何将一个String类型转换成Input Stream类型 大家帮我解释一下是为什么? 为什么没人理我的问题?就因为我给的分低吗?你们这些高手也太见钱眼开了吧 请问war是什么文件? SOS!SOS!SOS!我的页面有VRML场景,同时有javaAPPLET,怎样由场景向APPLET发送消息或交互 如何设置结果集,使其滚动 Java下如何将一幅图像加到另一幅图像上
{
public static void reflectCall(Object obj,String methodName,Class[] types,Object[] objs) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
{
Method callMethod=obj.getClass().getMethod(methodName, types);
callMethod.invoke(obj, objs);
}
public static void main(String args[]) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException
{
test temp=new test();
reflectCall(temp,"print", new Class[] {String.class},new Object[]{"1"});
}
}class test
{
public void print(String i)
{
System.out.println("atswtewtw");
} public void print(int i)
{
System.out.println(i);
}
}