int method1()
{
   int i=10;
   return i;
}
void method2(int x)
{
  ...
  ...
}
然后
就可以调用method2(method1());

解决方案 »

  1.   

    其实那应该是第二个方法有个返回值,然后将返回传给第一个方法吧。如:
    public int method1() {
      int i=0;
      ....
      return i;
    }
    public void method2(int i) {
      ...
    }
    public void method3() {
    ....
      method2(method1());
    ....
    }
    不知是不是这个意思?
      

  2.   

    c是可以用函数指针来实现,java是不行的。不过你可以把方法的名称作为参数传进去,然后根据名称去执行那个方法。如何根据方法名称字符串调用方法,看一下下面的代码。
    Class Cls = Class.forName("className");
    Object obj= Cls.newInstance();
    Method method = (Method)(Cls.getClass().getMethod("methodName");
    method.invoke(obj);
    这段代码是假设你要调用的方法是一个没有返回值和参数的方法
      

  3.   

    你是否要这样:
    import java.lang.reflect.*;public class TestMethod
    {
    public static void main(String args[])
    {
    TestMethod t = new TestMethod();
    t.test();
    }

    public void test()
    {
    try
    {
    Class[] cls = new Class[0];
    System.out.println("TestMethod 1 :");
    Method m1 = this.getClass().getDeclaredMethod("test1",cls);
    testMethod(this,m1);

    System.out.println("TestMethod 2 :");
    Method m2 = this.getClass().getDeclaredMethod("test2",cls);
    testMethod(this,m2);

    System.out.println("TestMethod 3 :");
    Method m3 = this.getClass().getDeclaredMethod("test3",cls);
    testMethod(this,m3);
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    }
    public String test1()
    {
    System.out.println("Test 1");
    return "t1";
    }
    public int test2()
    {
    System.out.println("Test 2");
    return 2;
    }
    public void test3()
    {
    System.out.println("Test 3");
    }
    public void testMethod(Object fromObj,Method method)
    {
    try
    {
    Object[] objs = new Object[0];
    Object obj = method.invoke(fromObj,objs);
    System.out.println("Return " + obj);
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    }
    }
      

  4.   

    to yuanqingfei (必定伟大) :应该是说用方法的返回值作为另外一个方法的参数吧?
      

  5.   

    thanks a lot 
    i will do my best to do what i should do.
    thank you all!!
    espcially
    to the one who get points
    ,...