比如一个类中有一个函数 void functionName() {
     callOtherFunction("functionName");
}有没有办法取得函数名称字符串呢?在callOtherFunction如果不通过指定的字符串传递能知道调用者是哪个函数吗?

解决方案 »

  1.   

    我也觉得不能 除非你在callOtherFunction中多弄一个参数表示调用的那个方法的名字
      

  2.   

    获取当前方法名很简单啊。
    根据当前的堆栈信息可以找出。
        void functionName() { 
            StackTraceElement[] sts = new Throwable().getStackTrace();
            String methodName = sts[0].getMethodName();
            callOtherFunction(methodName); 
        }