public static void testGetClassName() {
// 方法1:通过SecurityManager的保护方法getClassContext()
String clazzName = new SecurityManager() {
public String getClassName() {
return getClassContext()[1].getName();
}
}.getClassName();
System.out.println(clazzName);
// 方法2:通过Throwable的方法getStackTrace()
String clazzName2 = new Throwable().getStackTrace()[1].getClassName();
System.out.println(clazzName2);
// 方法3:通过分析匿名类名称()
String clazzName3 = new Object() {
public String getClassName() {
String clazzName = this.getClass().getName();
return clazzName.substring(0, clazzName.lastIndexOf('$'));
}
}.getClassName();
System.out.println(clazzName3);
//方法4:通过Thread的方法getStackTrace()
String clazzName4 = Thread.currentThread().getStackTrace()[2].getClassName();
System.out.println(clazzName4);
}
public static void testGetFunctionName() {
// 方法1:通过Throwable的方法getStackTrace()
String funcName2 = new Throwable().getStackTrace()[1].getMethodName();
System.out.println(funcName2);
//方法2:通过Thread的方法getStackTrace()
String clazzName4 = Thread.currentThread().getStackTrace()[2].getMethodName();
System.out.println(clazzName4);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有