package com.xxx.xxxx;

import java.lang.reflect.Method;

public class test {

    public static void main(String[] args) throws ClassNotFoundException{
                System.out.print(getTraceInfo());
    }
    
    public static String getTraceInfo() throws ClassNotFoundException{    
        StringBuffer sb = new StringBuffer();     
            
        StackTraceElement[] stacks = new Throwable().getStackTrace();    
        int stacksLen = stacks.length;    
        System.out.println(stacksLen);
//        Class clazz = Class.forName("java.lang.StringBuffer");
        Class<?> clazz = Class.forName(StackTraceElement.class.getName());
//        Class<?> clazz = Class.forName(test.class.getName());
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            String methodName = method.getName();
            System.out.println("方法名称:" + methodName);
            Class<?>[] parameterTypes = method.getParameterTypes();
            for (Class<?> clas : parameterTypes) {
                String parameterName = clas.getName();
                System.out.println("参数名称:" + parameterName);
            }
            System.out.println("*****************************");
        }
        sb.append("class: " ).append(stacks[1].getClassName()).append("; method: ").append(stacks[1].getMethodName()).append("; number: ").append(stacks[1].getLineNumber());    
            
        return sb.toString();    
    }    
}

 

相关文章:

  • 2021-07-11
  • 2021-10-18
  • 2022-02-20
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
相关资源
相似解决方案