if( temp==xxx )
  test();
else if( temp==xxx)
  test1();

解决方案 »

  1.   

    呵呵, java里没有函数指针的说, 否则就方便多了。
      

  2.   

    我给你一个类级的例子,方法一级的你自己参照完成,很容易的
                FunctionCode fc = FunctionCode.getInstance();
                String className = this.getClass().getName() + "$" +
                                   fc.get( FunctionID ).functionName;
                Class innerClass = Class.forName( className );
                Object[] initArgs = new Object[]{ this };
                Class[] paramTypes = new Class[]{ this.getClass() };
                Constructor innerConstr = innerClass.getConstructor( paramTypes );
                AbstractAction action = ( AbstractAction ) innerConstr.newInstance(
                                                initArgs );
      

  3.   

    用switch()
    case:1
        test1();  
        break;
    case2:
        test2();
        break;
    }
      

  4.   

    从库里取出的数据你把它变成INT型的放在switch(i)里面
      

  5.   

    首先不能用switch 和 if else数据库里会存放很多这样的映射信息java.lang.reflect 到底怎么样用??王文友的方法中FunctionCode 是什么意思呢??谢谢大家继续讨论
      

  6.   

    好象是不行的 只能用witch或者是if了
      

  7.   

    使用reflect可以判断函数名以及classname从而判断
    调用的函数是那个
      

  8.   

    那个跟你的应用无关
    你看看innerClass.getMethods()吧
    我所能提示你的就这些了,希望你不要太依赖于别人帮你完成,这对你自己的发展有利。
      

  9.   

    同意wangwenyou(王文友)~
    Java里面的反射API很灵活的说
      

  10.   

    指出一个错误,Java中应无“函数”一词。又抓到别人小辫子了,哈哈
      

  11.   

    类Constructor 有newinstance()这个方法来执行但是类method中 没有什么方法来执行我调用的函数阿?
      

  12.   

    invoke()
    同意dylanwolf(),用内部子类来代替你的方法也是一个好办法
    其实你使用无数个if  else也未尝不可,但不那样做是为了增强你的代码的可维护性。