java直接获得当前运行的类名以及方法名
发布日期:2021-06-24 18:50:21 浏览次数:2 分类:技术文章

本文共 612 字,大约阅读时间需要 2 分钟。

hot3.png

public class ClassUtils {    /**     * 获得当前方法名     * @return     */    public static String getCurrentMethodName() {        int level = 1;        StackTraceElement[] stacks = new Throwable().getStackTrace();        String methodName = stacks[level].getMethodName();        return methodName;    }    /**     * 获得当前类名     * @return     */    public static String getCurrentClassName() {        int level = 1;        StackTraceElement[] stacks = new Throwable().getStackTrace();        String className = stacks[level].getClassName();        return className;    }}

转载于:https://my.oschina.net/u/1177694/blog/820315

转载地址:https://blog.csdn.net/weixin_34248258/article/details/92082670 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Ecshop用户中心的收藏列表里显示商品缩略图
下一篇:Android ActionBar详解

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月26日 22时06分06秒