所以我有一个定义了两个公共方法的类。当我调用getDeclaredMethods,然后循环结果,打印名称,两者都会正确显示。因此不仅方法存在,反射调用也会找到它。
  
  
   但当我尝试调用该方法时,如下面的代码中所示,我会得到一个NoSuchMethodException。为什么它在调用时找不到它?
  
  public class Foo
{
  public byte[] read_status(Object arg)
  {
    byte[] test = new byte[10];
    for(int i = 0; i < 10; i++)
    {
      test[i] = (byte)i;
    }
    return test;
  }
  public int test(String s) throws Exception
  {
    Object r = this.getClass().getDeclaredMethod("read_status").invoke(this, (Object)s);
    byte[] bytes = (bytes[])r;
    for(int i = 0; i < bytes.length; i++)
    {
      System.out.println(""+bytes[i]);
    }
    return 0;
  }
}