Java获取当前类名的两种方法

适用于非静态方法

this.getClass().getName()

适用于静态方法

//获取类名
Thread.currentThread().getStackTrace()[1].getClassName()
//获取方法名
Thread.currentThread().getStackTrace()[1].getMethodName();
//获取行号
Thread.currentThread().getStackTrace()[1].getLineNumber();

猜你喜欢

转载自www.cnblogs.com/archer-wen/p/10638185.html