我是靠谱客的博主 友好发卡,这篇文章主要介绍@CallerSensitive注解,现在分享给大家,希望可以做个参考。

具体的理解请参考:https://blog.csdn.net/HEL_WOR/article/details/50199797。

下面是我自己的理解:下面就是Class.forName的定义,学过java的应该都用过这个方法。

复制代码
1
2
3
4
5
6
@CallerSensitive public static Class<?> forName(String className) throws ClassNotFoundException { Class<?> caller = Reflection.getCallerClass(); return forName0(className, true, ClassLoader.getClassLoader(caller), caller); }

进入Reflection中:发现getCallerClass是个native方法,并且被CallerSensitive注解

复制代码
1
2
@CallerSensitive public static native Class<?> getCallerClass();

继续查找srcsharenativesunreflectReflection.c。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "jvm.h" #include "sun_reflect_Reflection.h" JNIEXPORT jclass JNICALL Java_sun_reflect_Reflection_getCallerClass__ (JNIEnv *env, jclass unused) { return JVM_GetCallerClass(env, JVM_CALLER_DEPTH); } JNIEXPORT jclass JNICALL Java_sun_reflect_Reflection_getCallerClass__I (JNIEnv *env, jclass unused, jint depth) { return JVM_GetCallerClass(env, depth); }

看到JVM_CALLER_DEPTH应该就是上面博客提到的"固定深度",JVM_GetCallerClass这个方法是定义在jvm中,没有找到源代码,不过在jdk的安装目录:Javajdk1.8.0_25lib下面找到jvm.lib,使用nm命令查看:

在jvm.dll定义:


最后

以上就是友好发卡最近收集整理的关于@CallerSensitive注解的全部内容,更多相关@CallerSensitive注解内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(88)

评论列表共有 0 条评论

立即
投稿
返回
顶部