BBS水木清华站∶精华区
发信人: wingzhang (scott), 信区: Java
标 题: Re: 有关于Method getMethod(String,Class[])方法求助
发信站: BBS 水木清华站 (Mon Mar 8 17:58:42 1999)
【 在 sheen (笨笨熊-一切都会有的) 的大作中提到: 】
∶ Thank you, I have passed it, but not the desire I thought.
∶ 原先不成是因为我用的是forName(String)调用我的类,之后没有事例化,这是错误
∶ 原因。
∶ 我原先设想的是用自己的一个loadMethod(String ClassName,String MethodName)�
∶ 灵活地调用各个不同的类方法,但未果,因为在invoke(Object,Object[])时,
∶ ~~~~~~必须指定一个对象,
∶ 而在初始化对象事,如 MyMethods obj = new MyMethods();
∶ ~~~~~~~~~必须确定类名,这样就不能只通过
∶ 一个String ClassName 和 一个 String MethodName ,灵活地调用偶的方法,
∶ 现在,偶只好用一个土土的办法,就是将所有的方法放在一个类下,实现之,
∶ 仁兄,莫见笑,有何高见,please tell me!
how about following:
Class c = Class.forName("MyMethods");
Object obj = c.newInstance();
...
so you can have both the object and the method
--
※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 202.119.38.2]
BBS水木清华站∶精华区