jjzjj

getCallerClass

全部标签

java.lang.InternalError : CallerSensitive annotation expected at frame 1 错误

在静态方法中(用@CallerSensitive注释)我尝试获取调用类的名称:@CallerSensitivepublicstaticvoidsomeMethod(){Stringname=sun.reflect.Reflection.getCallerClass().getName();...}我得到错误:java.lang.InternalError:CallerSensitiveannotationexpectedatframe1这里有什么问题吗?引用资料http://www.infoq.com/news/2013/07/Oracle-Removes-getCallerClass

java - sun.reflect.Reflection.getCallerClass 替代方案

来自HowdoIfindthecallerofamethodusingstacktraceorreflection?(因为我没有足够的声誉在那里发表评论)由于sun.reflect.Reflection.getCallerClass在jdk8中已经被移除,有什么替代方案?如何使用sun.misc.SharedSecretsJavaLangAccessaccess=SharedSecrets.getJavaLangAccess();Throwablethrowable=newThrowable();intdepth=access.getStackTraceDepth(throwable)