zoukankan      html  css  js  c++  java
  • android获取当前行所属类和所属方法名

     
     
    第一种方法:
    String Method = Thread.currentThread().getStackTrace()[2].getMethodName();
     
    第二种方法:
    private static final boolean FINAL_CONSTANT_IS_LOCAL = true;
    private static final String TAG = FooProvider.class.getSimpleName();
     
    private void String getLogTagWithMethod() {
        if (FINAL_CONSTANT_IS_LOCAL) {
            Throwable stack = new Throwable().fillInStackTrace();
            StackTraceElement[] trace = stack.getStatckTrace();
            return trace[0].getClassName() + "." + trace[0].getMethodName() + ":" + trace[0].getLineNumber();
        } else {
            return TAG;
        }
    }
  • 相关阅读:
    A+B Problem
    迭代平方根
    猴子报数
    分数求和
    猴子吃桃
    钻石
    杨辉三角形
    MYSQL 5.7 修改密码、登录问题
    SQL 语句 explain 分析
    重构CMDB,避免运维之耻
  • 原文地址:https://www.cnblogs.com/On1Key/p/5175854.html
Copyright © 2011-2022 走看看