import java.lang.reflect.Method;      Class class0=this.getClass();
      Method[] methodList=class0.getMethods();
      for (int iM=0;iM<methodList.length;iM++ ) {
        System.out.println(methodList[iM].getName());
      }

解决方案 »

  1.   

    import java.io.PrintWriter;
    import java.io.StringWriter;public class Test
    {
    public static void main(String[] args)
    {
    theMethod();
    } private static void theMethod()
    {
    try
    {
    throw new Exception();
    }
    catch(Exception e)
    {
    System.out.println(getLastMethod(e));
    }
    } private static String getLastMethod(Exception e)
    {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    pw.flush();
    String trace = sw.toString(); int index1 = trace.indexOf("\tat ");
    int index2 = trace.indexOf(System.getProperty("line.separator"), index1 + 4);
    String lastCall = trace.substring(index1 + 4, index2);
    int index3 = lastCall.indexOf('(');
    String fullName = lastCall.substring(0, index3);
    return fullName; /*
    int index4 = fullName.lastIndexOf('.');
    String shortName = fullName.substring(index4 + 1);
    */
    }
    }