当前位置: 首页>>代码示例>>Java>>正文


Java Reflection.getCallerClass方法代码示例

本文整理汇总了Java中sun.reflect.Reflection.getCallerClass方法的典型用法代码示例。如果您正苦于以下问题:Java Reflection.getCallerClass方法的具体用法?Java Reflection.getCallerClass怎么用?Java Reflection.getCallerClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sun.reflect.Reflection的用法示例。


在下文中一共展示了Reflection.getCallerClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDrivers

import sun.reflect.Reflection; //导入方法依赖的package包/类
/**
 * Retrieves an Enumeration with all of the currently loaded JDBC drivers
 * to which the current caller has access.
 *
 * <P><B>Note:</B> The classname of a driver can be found using
 * <CODE>d.getClass().getName()</CODE>
 *
 * @return the list of JDBC Drivers loaded by the caller's class loader
 */
@CallerSensitive
public static java.util.Enumeration<Driver> getDrivers() {
    java.util.Vector<Driver> result = new java.util.Vector<>();

    Class<?> callerClass = Reflection.getCallerClass();

    // Walk through the loaded registeredDrivers.
    for(DriverInfo aDriver : registeredDrivers) {
        // If the caller does not have permission to load the driver then
        // skip it.
        if(isDriverAllowed(aDriver.driver, callerClass)) {
            result.addElement(aDriver.driver);
        } else {
            println("    skipping: " + aDriver.getClass().getName());
        }
    }
    return (result.elements());
}
 
开发者ID:madHEYsia,项目名称:ClassroomFlipkart,代码行数:28,代码来源:DriverManager.java

示例2: getDriver

import sun.reflect.Reflection; //导入方法依赖的package包/类
/**
 * Attempts to locate a driver that understands the given URL.
 * The <code>DriverManager</code> attempts to select an appropriate driver from
 * the set of registered JDBC drivers.
 *
 * @param url a database URL of the form
 *     <code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
 * @return a <code>Driver</code> object representing a driver
 * that can connect to the given URL
 * @exception SQLException if a database access error occurs
 */
@CallerSensitive
public static Driver getDriver(String url)
    throws SQLException {

    println("DriverManager.getDriver(\"" + url + "\")");

    Class<?> callerClass = Reflection.getCallerClass();

    // Walk through the loaded registeredDrivers attempting to locate someone
    // who understands the given URL.
    for (DriverInfo aDriver : registeredDrivers) {
        // If the caller does not have permission to load the driver then
        // skip it.
        if(isDriverAllowed(aDriver.driver, callerClass)) {
            try {
                if(aDriver.driver.acceptsURL(url)) {
                    // Success!
                    println("getDriver returning " + aDriver.driver.getClass().getName());
                return (aDriver.driver);
                }

            } catch(SQLException sqe) {
                // Drop through and try the next driver.
            }
        } else {
            println("    skipping: " + aDriver.driver.getClass().getName());
        }

    }

    println("getDriver: no suitable driver");
    throw new SQLException("No suitable driver", "08001");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:45,代码来源:DriverManager.java

示例3: forClass

import sun.reflect.Reflection; //导入方法依赖的package包/类
/**
 * Return the class in the local VM that this version is mapped to.  Null
 * is returned if there is no corresponding local class.
 *
 * @return  the <code>Class</code> instance that this descriptor represents
 */
@CallerSensitive
public Class<?> forClass() {
    if (cl == null) {
        return null;
    }
    requireInitialized();
    if (System.getSecurityManager() != null) {
        Class<?> caller = Reflection.getCallerClass();
        if (ReflectUtil.needsPackageAccessCheck(caller.getClassLoader(), cl.getClassLoader())) {
            ReflectUtil.checkPackageAccess(cl);
        }
    }
    return cl;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:ObjectStreamClass.java

示例4: deepest

import sun.reflect.Reflection; //导入方法依赖的package包/类
static void deepest() {
    // 0: Reflection 1: deepest 2: deeper 3: deep 4: Test.selfTest
    Class<?> c = Reflection.getCallerClass(4);
    assertEquals(c, Test.class);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:GetCallerClassWithDepth.java

示例5: doPrivilegedWithCombiner

import sun.reflect.Reflection; //导入方法依赖的package包/类
/**
 * Performs the specified {@code PrivilegedAction} with privileges
 * enabled and restricted by the specified
 * {@code AccessControlContext} and with a privilege scope limited
 * by specified {@code Permission} arguments.
 *
 * The action is performed with the intersection of the permissions
 * possessed by the caller's protection domain, and those possessed
 * by the domains represented by the specified
 * {@code AccessControlContext}.
 * <p>
 * If the action's {@code run} method throws an (unchecked) exception,
 * it will propagate through this method.
 *
 * <p> This method preserves the current AccessControlContext's
 * DomainCombiner (which may be null) while the action is performed.
 * <p>
 * If a security manager is installed and the specified
 * {@code AccessControlContext} was not created by system code and the
 * caller's {@code ProtectionDomain} has not been granted the
 * {@literal "createAccessControlContext"}
 * {@link java.security.SecurityPermission}, then the action is performed
 * with no permissions.
 *
 * @param <T> the type of the value returned by the PrivilegedAction's
 *                  {@code run} method.
 * @param action the action to be performed.
 * @param context an <i>access control context</i>
 *                representing the restriction to be applied to the
 *                caller's domain's privileges before performing
 *                the specified action.  If the context is
 *                {@code null},
 *                then no additional restriction is applied.
 * @param perms the {@code Permission} arguments which limit the
 *              scope of the caller's privileges. The number of arguments
 *              is variable.
 *
 * @return the value returned by the action's {@code run} method.
 *
 * @throws NullPointerException if action or perms or any element of
 *         perms is {@code null}
 *
 * @see #doPrivileged(PrivilegedAction)
 * @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext)
 * @see java.security.DomainCombiner
 *
 * @since 1.8
 */
@CallerSensitive
public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action,
    AccessControlContext context, Permission... perms) {

    AccessControlContext parent = getContext();
    DomainCombiner dc = parent.getCombiner();
    if (dc == null && context != null) {
        dc = context.getCombiner();
    }
    if (perms == null) {
        throw new NullPointerException("null permissions parameter");
    }
    Class <?> caller = Reflection.getCallerClass();
    return AccessController.doPrivileged(action, createWrapper(dc, caller,
        parent, context, perms));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:65,代码来源:AccessController.java

示例6: newInstance

import sun.reflect.Reflection; //导入方法依赖的package包/类
/**
 * Uses the constructor represented by this {@code Constructor} object to
 * create and initialize a new instance of the constructor's
 * declaring class, with the specified initialization parameters.
 * Individual parameters are automatically unwrapped to match
 * primitive formal parameters, and both primitive and reference
 * parameters are subject to method invocation conversions as necessary.
 *
 * <p>If the number of formal parameters required by the underlying constructor
 * is 0, the supplied {@code initargs} array may be of length 0 or null.
 *
 * <p>If the constructor's declaring class is an inner class in a
 * non-static context, the first argument to the constructor needs
 * to be the enclosing instance; see section 15.9.3 of
 * <cite>The Java&trade; Language Specification</cite>.
 *
 * <p>If the required access and argument checks succeed and the
 * instantiation will proceed, the constructor's declaring class
 * is initialized if it has not already been initialized.
 *
 * <p>If the constructor completes normally, returns the newly
 * created and initialized instance.
 *
 * @param initargs array of objects to be passed as arguments to
 * the constructor call; values of primitive types are wrapped in
 * a wrapper object of the appropriate type (e.g. a {@code float}
 * in a {@link java.lang.Float Float})
 *
 * @return a new object created by calling the constructor
 * this object represents
 *
 * @exception IllegalAccessException    if this {@code Constructor} object
 *              is enforcing Java language access control and the underlying
 *              constructor is inaccessible.
 * @exception IllegalArgumentException  if the number of actual
 *              and formal parameters differ; if an unwrapping
 *              conversion for primitive arguments fails; or if,
 *              after possible unwrapping, a parameter value
 *              cannot be converted to the corresponding formal
 *              parameter type by a method invocation conversion; if
 *              this constructor pertains to an enum type.
 * @exception InstantiationException    if the class that declares the
 *              underlying constructor represents an abstract class.
 * @exception InvocationTargetException if the underlying constructor
 *              throws an exception.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 */
@CallerSensitive
public T newInstance(Object ... initargs)
    throws InstantiationException, IllegalAccessException,
           IllegalArgumentException, InvocationTargetException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, null, modifiers);
        }
    }
    if ((clazz.getModifiers() & Modifier.ENUM) != 0)
        throw new IllegalArgumentException("Cannot reflectively create enum objects");
    ConstructorAccessor ca = constructorAccessor;   // read volatile
    if (ca == null) {
        ca = acquireConstructorAccessor();
    }
    @SuppressWarnings("unchecked")
    T inst = (T) ca.newInstance(initargs);
    return inst;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:70,代码来源:Constructor.java

示例7: setLong

import sun.reflect.Reflection; //导入方法依赖的package包/类
/**
 * Sets the value of a field as a {@code long} on the specified object.
 * This method is equivalent to
 * {@code set(obj, lObj)},
 * where {@code lObj} is a {@code Long} object and
 * {@code lObj.longValue() == l}.
 *
 * @param obj the object whose field should be modified
 * @param l   the new value for the field of {@code obj}
 * being modified
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is either inaccessible or final.
 * @exception IllegalArgumentException  if the specified object is not an
 *              instance of the class or interface declaring the underlying
 *              field (or a subclass or implementor thereof),
 *              or if an unwrapping conversion fails.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#set
 */
@CallerSensitive
public void setLong(Object obj, long l)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    getFieldAccessor(obj).setLong(obj, l);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:Field.java

示例8: setBoolean

import sun.reflect.Reflection; //导入方法依赖的package包/类
/**
 * Sets the value of a field as a {@code boolean} on the specified object.
 * This method is equivalent to
 * {@code set(obj, zObj)},
 * where {@code zObj} is a {@code Boolean} object and
 * {@code zObj.booleanValue() == z}.
 *
 * @param obj the object whose field should be modified
 * @param z   the new value for the field of {@code obj}
 * being modified
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is either inaccessible or final.
 * @exception IllegalArgumentException  if the specified object is not an
 *              instance of the class or interface declaring the underlying
 *              field (or a subclass or implementor thereof),
 *              or if an unwrapping conversion fails.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#set
 */
@CallerSensitive
public void setBoolean(Object obj, boolean z)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    getFieldAccessor(obj).setBoolean(obj, z);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:Field.java

示例9: doPrivileged

import sun.reflect.Reflection; //导入方法依赖的package包/类
/**
 * Performs the specified {@code PrivilegedAction} with privileges
 * enabled and restricted by the specified
 * {@code AccessControlContext} and with a privilege scope limited
 * by specified {@code Permission} arguments.
 *
 * The action is performed with the intersection of the permissions
 * possessed by the caller's protection domain, and those possessed
 * by the domains represented by the specified
 * {@code AccessControlContext}.
 * <p>
 * If the action's {@code run} method throws an (unchecked) exception,
 * it will propagate through this method.
 * <p>
 * If a security manager is installed and the specified
 * {@code AccessControlContext} was not created by system code and the
 * caller's {@code ProtectionDomain} has not been granted the
 * {@literal "createAccessControlContext"}
 * {@link java.security.SecurityPermission}, then the action is performed
 * with no permissions.
 *
 * @param <T> the type of the value returned by the PrivilegedAction's
 *                  {@code run} method.
 * @param action the action to be performed.
 * @param context an <i>access control context</i>
 *                representing the restriction to be applied to the
 *                caller's domain's privileges before performing
 *                the specified action.  If the context is
 *                {@code null},
 *                then no additional restriction is applied.
 * @param perms the {@code Permission} arguments which limit the
 *              scope of the caller's privileges. The number of arguments
 *              is variable.
 *
 * @return the value returned by the action's {@code run} method.
 *
 * @throws NullPointerException if action or perms or any element of
 *         perms is {@code null}
 *
 * @see #doPrivileged(PrivilegedAction)
 * @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext)
 *
 * @since 1.8
 */
@CallerSensitive
public static <T> T doPrivileged(PrivilegedAction<T> action,
    AccessControlContext context, Permission... perms) {

    AccessControlContext parent = getContext();
    if (perms == null) {
        throw new NullPointerException("null permissions parameter");
    }
    Class <?> caller = Reflection.getCallerClass();
    return AccessController.doPrivileged(action, createWrapper(null,
        caller, parent, context, perms));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:57,代码来源:AccessController.java

示例10: doPrivileged

import sun.reflect.Reflection; //导入方法依赖的package包/类
/**
 * Performs the specified {@code PrivilegedExceptionAction} with
 * privileges enabled and restricted by the specified
 * {@code AccessControlContext} and with a privilege scope limited by
 * specified {@code Permission} arguments.
 *
 * The action is performed with the intersection of the permissions
 * possessed by the caller's protection domain, and those possessed
 * by the domains represented by the specified
 * {@code AccessControlContext}.
 * <p>
 * If the action's {@code run} method throws an (unchecked) exception,
 * it will propagate through this method.
 * <p>
 * If a security manager is installed and the specified
 * {@code AccessControlContext} was not created by system code and the
 * caller's {@code ProtectionDomain} has not been granted the
 * {@literal "createAccessControlContext"}
 * {@link java.security.SecurityPermission}, then the action is performed
 * with no permissions.
 *
 * @param <T> the type of the value returned by the
 *                  PrivilegedExceptionAction's {@code run} method.
 * @param action the action to be performed.
 * @param context an <i>access control context</i>
 *                representing the restriction to be applied to the
 *                caller's domain's privileges before performing
 *                the specified action.  If the context is
 *                {@code null},
 *                then no additional restriction is applied.
 * @param perms the {@code Permission} arguments which limit the
 *              scope of the caller's privileges. The number of arguments
 *              is variable.
 *
 * @return the value returned by the action's {@code run} method.
 *
 * @throws PrivilegedActionException if the specified action's
 *         {@code run} method threw a <i>checked</i> exception
 * @throws NullPointerException if action or perms or any element of
 *         perms is {@code null}
 *
 * @see #doPrivileged(PrivilegedAction)
 * @see #doPrivileged(PrivilegedAction,AccessControlContext)
 *
 * @since 1.8
 */
@CallerSensitive
public static <T> T doPrivileged(PrivilegedExceptionAction<T> action,
                                 AccessControlContext context, Permission... perms)
    throws PrivilegedActionException
{
    AccessControlContext parent = getContext();
    if (perms == null) {
        throw new NullPointerException("null permissions parameter");
    }
    Class <?> caller = Reflection.getCallerClass();
    return AccessController.doPrivileged(action, createWrapper(null, caller, parent, context, perms));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:59,代码来源:AccessController.java

示例11: forName

import sun.reflect.Reflection; //导入方法依赖的package包/类
/**
 * Returns the {@code Class} object associated with the class or
 * interface with the given string name.  Invoking this method is
 * equivalent to:
 *
 * <blockquote>
 *  {@code Class.forName(className, true, currentLoader)}
 * </blockquote>
 *
 * where {@code currentLoader} denotes the defining class loader of
 * the current class.
 *
 * <p> For example, the following code fragment returns the
 * runtime {@code Class} descriptor for the class named
 * {@code java.lang.Thread}:
 *
 * <blockquote>
 *   {@code Class t = Class.forName("java.lang.Thread")}
 * </blockquote>
 * <p>
 * A call to {@code forName("X")} causes the class named
 * {@code X} to be initialized.
 *
 * @param      className   the fully qualified name of the desired class.
 * @return     the {@code Class} object for the class with the
 *             specified name.
 * @exception LinkageError if the linkage fails
 * @exception ExceptionInInitializerError if the initialization provoked
 *            by this method fails
 * @exception ClassNotFoundException if the class cannot be located
 */
@CallerSensitive
public static Class<?> forName(String className)
            throws ClassNotFoundException {
    Class<?> caller = Reflection.getCallerClass();
    return forName0(className, true, ClassLoader.getClassLoader(caller), caller);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:Class.java

示例12: setShort

import sun.reflect.Reflection; //导入方法依赖的package包/类
/**
 * Sets the value of a field as a {@code short} on the specified object.
 * This method is equivalent to
 * {@code set(obj, sObj)},
 * where {@code sObj} is a {@code Short} object and
 * {@code sObj.shortValue() == s}.
 *
 * @param obj the object whose field should be modified
 * @param s   the new value for the field of {@code obj}
 * being modified
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is either inaccessible or final.
 * @exception IllegalArgumentException  if the specified object is not an
 *              instance of the class or interface declaring the underlying
 *              field (or a subclass or implementor thereof),
 *              or if an unwrapping conversion fails.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#set
 */
@CallerSensitive
public void setShort(Object obj, short s)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    getFieldAccessor(obj).setShort(obj, s);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:Field.java

示例13: getLong

import sun.reflect.Reflection; //导入方法依赖的package包/类
/**
 * Gets the value of a static or instance field of type
 * {@code long} or of another primitive type convertible to
 * type {@code long} via a widening conversion.
 *
 * @param obj the object to extract the {@code long} value
 * from
 * @return the value of the field converted to type {@code long}
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not
 *              an instance of the class or interface declaring the
 *              underlying field (or a subclass or implementor
 *              thereof), or if the field value cannot be
 *              converted to the type {@code long} by a
 *              widening conversion.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see       Field#get
 */
@CallerSensitive
public long getLong(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).getLong(obj);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:Field.java

示例14: getChar

import sun.reflect.Reflection; //导入方法依赖的package包/类
/**
 * Gets the value of a static or instance field of type
 * {@code char} or of another primitive type convertible to
 * type {@code char} via a widening conversion.
 *
 * @param obj the object to extract the {@code char} value
 * from
 * @return the value of the field converted to type {@code char}
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is inaccessible.
 * @exception IllegalArgumentException  if the specified object is not
 *              an instance of the class or interface declaring the
 *              underlying field (or a subclass or implementor
 *              thereof), or if the field value cannot be
 *              converted to the type {@code char} by a
 *              widening conversion.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 * @see Field#get
 */
@CallerSensitive
public char getChar(Object obj)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    return getFieldAccessor(obj).getChar(obj);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:37,代码来源:Field.java

示例15: set

import sun.reflect.Reflection; //导入方法依赖的package包/类
/**
 * Sets the field represented by this {@code Field} object on the
 * specified object argument to the specified new value. The new
 * value is automatically unwrapped if the underlying field has a
 * primitive type.
 *
 * <p>The operation proceeds as follows:
 *
 * <p>If the underlying field is static, the {@code obj} argument is
 * ignored; it may be null.
 *
 * <p>Otherwise the underlying field is an instance field.  If the
 * specified object argument is null, the method throws a
 * {@code NullPointerException}.  If the specified object argument is not
 * an instance of the class or interface declaring the underlying
 * field, the method throws an {@code IllegalArgumentException}.
 *
 * <p>If this {@code Field} object is enforcing Java language access control, and
 * the underlying field is inaccessible, the method throws an
 * {@code IllegalAccessException}.
 *
 * <p>If the underlying field is final, the method throws an
 * {@code IllegalAccessException} unless {@code setAccessible(true)}
 * has succeeded for this {@code Field} object
 * and the field is non-static. Setting a final field in this way
 * is meaningful only during deserialization or reconstruction of
 * instances of classes with blank final fields, before they are
 * made available for access by other parts of a program. Use in
 * any other context may have unpredictable effects, including cases
 * in which other parts of a program continue to use the original
 * value of this field.
 *
 * <p>If the underlying field is of a primitive type, an unwrapping
 * conversion is attempted to convert the new value to a value of
 * a primitive type.  If this attempt fails, the method throws an
 * {@code IllegalArgumentException}.
 *
 * <p>If, after possible unwrapping, the new value cannot be
 * converted to the type of the underlying field by an identity or
 * widening conversion, the method throws an
 * {@code IllegalArgumentException}.
 *
 * <p>If the underlying field is static, the class that declared the
 * field is initialized if it has not already been initialized.
 *
 * <p>The field is set to the possibly unwrapped and widened new value.
 *
 * <p>If the field is hidden in the type of {@code obj},
 * the field's value is set according to the preceding rules.
 *
 * @param obj the object whose field should be modified
 * @param value the new value for the field of {@code obj}
 * being modified
 *
 * @exception IllegalAccessException    if this {@code Field} object
 *              is enforcing Java language access control and the underlying
 *              field is either inaccessible or final.
 * @exception IllegalArgumentException  if the specified object is not an
 *              instance of the class or interface declaring the underlying
 *              field (or a subclass or implementor thereof),
 *              or if an unwrapping conversion fails.
 * @exception NullPointerException      if the specified object is null
 *              and the field is an instance field.
 * @exception ExceptionInInitializerError if the initialization provoked
 *              by this method fails.
 */
@CallerSensitive
public void set(Object obj, Object value)
    throws IllegalArgumentException, IllegalAccessException
{
    if (!override) {
        if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
            Class<?> caller = Reflection.getCallerClass();
            checkAccess(caller, clazz, obj, modifiers);
        }
    }
    getFieldAccessor(obj).set(obj, value);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:79,代码来源:Field.java


注:本文中的sun.reflect.Reflection.getCallerClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。