BBS水木清华站∶精华区

发信人: wingzhang (scott), 信区: Java        
标  题: Re: 有关于Method getMethod(String,Class[])方法求助 
发信站: BBS 水木清华站 (Mon Mar  8 10:43:49 1999) 
 
【 在 sheen (星矢胖胖熊-一切都会有的) 的大作中提到: 】 
 I have try, but the same result: 无法调用此方法 
 
Can you put out your method signature? 
I have passed the following examples: 
 
import java.lang.reflect.*; 
 
public class TestM { 
public static void main(String[] args){ 
   try{ 
  TestM t = new TestM(); 
  Class c = t.getClass(); 
  Class[] cargs = new Class[2]; 
  String[] realArgs = {"aa","bb"}; 
  cargs[0] = realArgs.getClass(); 
  Integer in = new Integer(2); 
  cargs[1] = in.getClass(); 
  Method m = c.getMethod("test",cargs); 
  Object[] inArgs = new Object[2]; 
  inArgs[0] = readArgs; 
  inArgs[1] = in; 
  m.invoke(t,inArgs); 
 }catch(Exception e){System.out.println(e);} 

 
 public void test(String[] str,Integer stri){ 
   for(int j = 0; j < str.length; j ++) 
   System.out.println(str[j]); 
   System.out.println(stri.intValue()); 



 
-- 
※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 202.119.38.2] 

BBS水木清华站∶精华区