向经常用反射的人求个通用的函数 最近程序里频繁用到反射,我想向大家求个通用的几个函数类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正则表达式 请问怎么从BufferedImage image得到byte[]数据。 关于梦幻西游遇怪问题。希望个位来帮下 数据库驱动的问题 求助swing问题 Result 类有哪些常用方法呀? ______linux平台上的 Java 基础问题_____ 怪事!!!TextArea控件无法显示数组呀??? java applet 不能運行? 经验交流系列一:J2SE、J2EE、J2ME介绍,资源介绍及常见问题分析解决!(++继续++) 如何设置结果集,使其滚动 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);
}
}