本文介绍了sun.reflect.CallerSensitive注释是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@CallerSensitive 注释上面的方法是什么意思?

What is implied by @CallerSensitive annotation above methods?

例如,注释存在于getClassLoader方法

For example,the annotation is present in getClassLoader method of Class

 @CallerSensitive
    public ClassLoader getClassLoader() {
    //
    }


推荐答案

根据JEP还),

如果你看一下 Class#forName(String)的实现

@CallerSensitive
public static Class<?> forName(String className)
            throws ClassNotFoundException {
    return forName0(className, true,
                    ClassLoader.getClassLoader(Reflection.getCallerClass()));
}

,您会注意到它正在使用。如果我们看看那个方法

, you notice that it is using Reflection.getCallerClass(). If we look at that method



@CallerSensitive
public static native Class getCallerClass();

问题似乎在这个JEP之前是,如果调用者敏感方法是通过反射调用而不是直接地,必须有一个复杂的过程来识别实际的调用类是什么。这是有问题的,如果方法通过反射调用。使用 @CallerSensitive 建议(并介绍)一个更简单的过程。

The problem, it seems, before this JEP, was that if the caller sensitive method was called through reflection instead of directly, there had to be a complex process to identify what the actual calling class was. This was problematic if the method was invoked through reflection. A simpler process was proposed (and introduced) with @CallerSensitive.

基本上, @CallerSensitive 注释由JVM使用

Basically, the @CallerSensitive annotation is used by the JVM

这篇关于sun.reflect.CallerSensitive注释是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 06:09