JAVA中获取当前运行的类名,方法名,行数


JAVA中获取当前运行的类名,方法名,行数

public static String getTraceInfo(){    
        StringBuffer sb = new StringBuffer();     
            
        StackTraceElement[] stacks = new Throwable().getStackTrace();    
        int stacksLen = stacks.length;    
        sb.append("class: " ).append(stacks[1].getClassName()).append("; method: ").append(stacks[1].getMethodName()).append("; number: ").append(stacks[1].getLineNumber());    
            
        return sb.toString();    
    }    

String _methodName =  
  
new Exception().getStackTrace()[1].getMethodName();// 获得调用者的方法名  
  
String _thisMethodName =  
  
new Exception().getStackTrace()[0].getMethodName();// 获得当前的方法名 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM