jdk/src/share/classes/java/lang/reflect/Field.java
author sherman
Tue, 30 Aug 2011 11:53:11 -0700
changeset 10419 12c063b39232
parent 10342 ca0984bc9d32
child 14342 8435a30053c1
permissions -rw-r--r--
7084245: Update usages of InternalError to use exception chaining Summary: to use new InternalError constructor with cause chainning Reviewed-by: alanb, ksrini, xuelei, neugens Contributed-by: sebastian.sickelmann@gmx.de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
     2
 * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang.reflect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.reflect.FieldAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.reflect.Reflection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.reflect.generics.repository.FieldRepository;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.reflect.generics.factory.CoreReflectionFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.reflect.generics.factory.GenericsFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.reflect.generics.scope.ClassScope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.lang.annotation.Annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.reflect.annotation.AnnotationParser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * A {@code Field} provides information about, and dynamic access to, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * single field of a class or an interface.  The reflected field may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * be a class (static) field or an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>A {@code Field} permits widening conversions to occur during a get or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * set access operation, but throws an {@code IllegalArgumentException} if a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * narrowing conversion would occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @see Member
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @see java.lang.Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @see java.lang.Class#getFields()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @see java.lang.Class#getField(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see java.lang.Class#getDeclaredFields()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see java.lang.Class#getDeclaredField(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @author Kenneth Russell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @author Nakul Saraiya
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public final
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
class Field extends AccessibleObject implements Member {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2174
diff changeset
    61
    private Class<?>            clazz;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private int                 slot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // This is guaranteed to be interned by the VM in the 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // reflection implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private String              name;
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2174
diff changeset
    66
    private Class<?>            type;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private int                 modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // Generics and annotations support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private transient String    signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // generic info repository; lazily initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private transient FieldRepository genericInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private byte[]              annotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // Cached field accessor created without override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private FieldAccessor fieldAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    // Cached field accessor created with override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private FieldAccessor overrideFieldAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // For sharing of FieldAccessors. This branching structure is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    // currently only two levels deep (i.e., one root Field and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    // potentially many Field objects pointing to it.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private Field               root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // Generics infrastructure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private String getGenericSignature() {return signature;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // Accessor for factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private GenericsFactory getFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        Class<?> c = getDeclaringClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        // create scope and factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return CoreReflectionFactory.make(c, ClassScope.make(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    // Accessor for generic info repository
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private FieldRepository getGenericInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        // lazily initialize repository if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (genericInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            // create and cache generic info repository
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            genericInfo = FieldRepository.make(getGenericSignature(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                               getFactory());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return genericInfo; //return cached repository
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Package-private constructor used by ReflectAccess to enable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * instantiation of these objects in Java code from the java.lang
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * package via sun.reflect.LangReflectAccess.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2174
diff changeset
   110
    Field(Class<?> declaringClass,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
          String name,
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2174
diff changeset
   112
          Class<?> type,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
          int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
          int slot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
          String signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
          byte[] annotations)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        this.clazz = declaringClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.modifiers = modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.slot = slot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        this.signature = signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        this.annotations = annotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Package-private routine (exposed to java.lang.Class via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * ReflectAccess) which returns a copy of this Field. The copy's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * "root" field points to this Field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    Field copy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        // This routine enables sharing of FieldAccessor objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // among Field objects which refer to the same underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        // method in the VM. (All of this contortion is only necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        // because of the "accessibility" bit in AccessibleObject,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        // which implicitly requires that new java.lang.reflect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // objects be fabricated for each reflective call on Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        // objects.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        res.root = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        // Might as well eagerly propagate this if already present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        res.fieldAccessor = fieldAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        res.overrideFieldAccessor = overrideFieldAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Returns the {@code Class} object representing the class or interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * that declares the field represented by this {@code Field} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public Class<?> getDeclaringClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Returns the name of the field represented by this {@code Field} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * Returns the Java language modifiers for the field represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * by this {@code Field} object, as an integer. The {@code Modifier} class should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * be used to decode the modifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @see Modifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public int getModifiers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        return modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Returns {@code true} if this field represents an element of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * an enumerated type; returns {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @return {@code true} if and only if this field represents an element of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * an enumerated type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public boolean isEnumConstant() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return (getModifiers() & Modifier.ENUM) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Returns {@code true} if this field is a synthetic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * field; returns {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @return true if and only if this field is a synthetic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * field as defined by the Java Language Specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public boolean isSynthetic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return Modifier.isSynthetic(getModifiers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Returns a {@code Class} object that identifies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * declared type for the field represented by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * {@code Field} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @return a {@code Class} object identifying the declared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * type of the field represented by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public Class<?> getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Returns a {@code Type} object that represents the declared type for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * the field represented by this {@code Field} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * <p>If the {@code Type} is a parameterized type, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * {@code Type} object returned must accurately reflect the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * actual type parameters used in the source code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * <p>If the type of the underlying field is a type variable or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * parameterized type, it is created. Otherwise, it is resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @return a {@code Type} object that represents the declared type for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *     the field represented by this {@code Field} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @throws GenericSignatureFormatError if the generic field
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 9029
diff changeset
   224
     *     signature does not conform to the format specified in
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 9029
diff changeset
   225
     *     <cite>The Java&trade; Virtual Machine Specification</cite>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @throws TypeNotPresentException if the generic type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *     signature of the underlying field refers to a non-existent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *     type declaration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @throws MalformedParameterizedTypeException if the generic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *     signature of the underlying field refers to a parameterized type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *     that cannot be instantiated for any reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public Type getGenericType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if (getGenericSignature() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            return getGenericInfo().getGenericType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            return getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Compares this {@code Field} against the specified object.  Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * true if the objects are the same.  Two {@code Field} objects are the same if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * they were declared by the same class and have the same name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * and type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (obj != null && obj instanceof Field) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            Field other = (Field)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            return (getDeclaringClass() == other.getDeclaringClass())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                && (getName() == other.getName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                && (getType() == other.getType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Returns a hashcode for this {@code Field}.  This is computed as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * exclusive-or of the hashcodes for the underlying field's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * declaring class name and its name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Returns a string describing this {@code Field}.  The format is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * the access modifiers for the field, if any, followed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * by the field type, followed by a space, followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * the fully-qualified name of the class declaring the field,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * followed by a period, followed by the name of the field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *    public static final int java.lang.Thread.MIN_PRIORITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *    private int java.io.FileDescriptor.fd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <p>The modifiers are placed in canonical order as specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * "The Java Language Specification".  This is {@code public},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * {@code protected} or {@code private} first, and then other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * modifiers in the following order: {@code static}, {@code final},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * {@code transient}, {@code volatile}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        int mod = getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            + getTypeName(getType()) + " "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            + getTypeName(getDeclaringClass()) + "."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            + getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Returns a string describing this {@code Field}, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * its generic type.  The format is the access modifiers for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * field, if any, followed by the generic field type, followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * a space, followed by the fully-qualified name of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * declaring the field, followed by a period, followed by the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * of the field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * <p>The modifiers are placed in canonical order as specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * "The Java Language Specification".  This is {@code public},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * {@code protected} or {@code private} first, and then other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * modifiers in the following order: {@code static}, {@code final},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * {@code transient}, {@code volatile}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @return a string describing this {@code Field}, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * its generic type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public String toGenericString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        int mod = getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        Type fieldType = getGenericType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            +  ((fieldType instanceof Class) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                getTypeName((Class)fieldType): fieldType.toString())+ " "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            + getTypeName(getDeclaringClass()) + "."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            + getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Returns the value of the field represented by this {@code Field}, on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * the specified object. The value is automatically wrapped in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * object if it has a primitive type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * <p>The underlying field's value is obtained as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * <p>If the underlying field is a static field, the {@code obj} argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * is ignored; it may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * <p>Otherwise, the underlying field is an instance field.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * specified {@code obj} argument is null, the method throws a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * {@code NullPointerException}. If the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * field, the method throws an {@code IllegalArgumentException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   338
     * <p>If this {@code Field} object is enforcing Java language access control, and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * the underlying field is inaccessible, the method throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * {@code IllegalAccessException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * If the underlying field is static, the class that declared the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * field is initialized if it has not already been initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * <p>Otherwise, the value is retrieved from the underlying instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * or static field.  If the field has a primitive type, the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * is wrapped in an object before being returned, otherwise it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * returned as is.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * <p>If the field is hidden in the type of {@code obj},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * the field's value is obtained according to the preceding rules.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @param obj object from which the represented field's value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * to be extracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @return the value of the represented field in object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * {@code obj}; primitive values are wrapped in an appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * object before being returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   358
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   359
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   360
     *              field is inaccessible.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *              field (or a subclass or implementor thereof).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    public Object get(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return getFieldAccessor(obj).get(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * Gets the value of a static or instance {@code boolean} field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @param obj the object to extract the {@code boolean} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @return the value of the {@code boolean} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   382
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   383
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   384
     *              field is inaccessible.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *              converted to the type {@code boolean} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @see       Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public boolean getBoolean(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return getFieldAccessor(obj).getBoolean(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Gets the value of a static or instance {@code byte} field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @param obj the object to extract the {@code byte} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @return the value of the {@code byte} field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   410
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   411
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   412
     *              field is inaccessible.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *              converted to the type {@code byte} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @see       Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    public byte getByte(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        return getFieldAccessor(obj).getByte(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Gets the value of a static or instance field of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * {@code char} or of another primitive type convertible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * type {@code char} via a widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @param obj the object to extract the {@code char} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @return the value of the field converted to type {@code char}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   440
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   441
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   442
     *              field is inaccessible.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *              converted to the type {@code char} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @see Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    public char getChar(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        return getFieldAccessor(obj).getChar(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * Gets the value of a static or instance field of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * {@code short} or of another primitive type convertible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * type {@code short} via a widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @param obj the object to extract the {@code short} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @return the value of the field converted to type {@code short}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   470
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   471
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   472
     *              field is inaccessible.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *              converted to the type {@code short} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @see       Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    public short getShort(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        return getFieldAccessor(obj).getShort(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * Gets the value of a static or instance field of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * {@code int} or of another primitive type convertible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * type {@code int} via a widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @param obj the object to extract the {@code int} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @return the value of the field converted to type {@code int}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   500
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   501
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   502
     *              field is inaccessible.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *              converted to the type {@code int} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @see       Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    public int getInt(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        return getFieldAccessor(obj).getInt(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * Gets the value of a static or instance field of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * {@code long} or of another primitive type convertible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * type {@code long} via a widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @param obj the object to extract the {@code long} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @return the value of the field converted to type {@code long}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   530
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   531
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   532
     *              field is inaccessible.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *              converted to the type {@code long} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @see       Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public long getLong(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        return getFieldAccessor(obj).getLong(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * Gets the value of a static or instance field of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * {@code float} or of another primitive type convertible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * type {@code float} via a widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @param obj the object to extract the {@code float} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @return the value of the field converted to type {@code float}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   560
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   561
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   562
     *              field is inaccessible.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     *              converted to the type {@code float} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @see Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    public float getFloat(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        return getFieldAccessor(obj).getFloat(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * Gets the value of a static or instance field of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * {@code double} or of another primitive type convertible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * type {@code double} via a widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @param obj the object to extract the {@code double} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @return the value of the field converted to type {@code double}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   590
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   591
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   592
     *              field is inaccessible.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * @exception IllegalArgumentException  if the specified object is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     *              an instance of the class or interface declaring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *              underlying field (or a subclass or implementor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *              thereof), or if the field value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *              converted to the type {@code double} by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     *              widening conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @see       Field#get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    public double getDouble(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        return getFieldAccessor(obj).getDouble(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * Sets the field represented by this {@code Field} object on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * specified object argument to the specified new value. The new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * value is automatically unwrapped if the underlying field has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * primitive type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * <p>The operation proceeds as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * <p>If the underlying field is static, the {@code obj} argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * ignored; it may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * <p>Otherwise the underlying field is an instance field.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * specified object argument is null, the method throws a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * {@code NullPointerException}.  If the specified object argument is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * an instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * field, the method throws an {@code IllegalArgumentException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   628
     * <p>If this {@code Field} object is enforcing Java language access control, and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * the underlying field is inaccessible, the method throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * {@code IllegalAccessException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * <p>If the underlying field is final, the method throws an
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   633
     * {@code IllegalAccessException} unless {@code setAccessible(true)}
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   634
     * has succeeded for this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   635
     * and the field is non-static. Setting a final field in this way
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * is meaningful only during deserialization or reconstruction of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * instances of classes with blank final fields, before they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * made available for access by other parts of a program. Use in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * any other context may have unpredictable effects, including cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * in which other parts of a program continue to use the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * value of this field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * <p>If the underlying field is of a primitive type, an unwrapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * conversion is attempted to convert the new value to a value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * a primitive type.  If this attempt fails, the method throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * {@code IllegalArgumentException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * <p>If, after possible unwrapping, the new value cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * converted to the type of the underlying field by an identity or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * widening conversion, the method throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * {@code IllegalArgumentException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * <p>If the underlying field is static, the class that declared the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * field is initialized if it has not already been initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * <p>The field is set to the possibly unwrapped and widened new value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * <p>If the field is hidden in the type of {@code obj},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * the field's value is set according to the preceding rules.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * @param value the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   665
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   666
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   667
     *              field is either inaccessible or final.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    public void set(Object obj, Object value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        getFieldAccessor(obj).set(obj, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * Sets the value of a field as a {@code boolean} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * {@code set(obj, zObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * where {@code zObj} is a {@code Boolean} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * {@code zObj.booleanValue() == z}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * @param z   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   694
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   695
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   696
     *              field is either inaccessible or final.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    public void setBoolean(Object obj, boolean z)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        getFieldAccessor(obj).setBoolean(obj, z);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * Sets the value of a field as a {@code byte} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * {@code set(obj, bObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * where {@code bObj} is a {@code Byte} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * {@code bObj.byteValue() == b}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * @param b   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   724
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   725
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   726
     *              field is either inaccessible or final.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    public void setByte(Object obj, byte b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        getFieldAccessor(obj).setByte(obj, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * Sets the value of a field as a {@code char} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * {@code set(obj, cObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * where {@code cObj} is a {@code Character} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * {@code cObj.charValue() == c}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * @param c   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   754
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   755
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   756
     *              field is either inaccessible or final.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    public void setChar(Object obj, char c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        getFieldAccessor(obj).setChar(obj, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * Sets the value of a field as a {@code short} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * {@code set(obj, sObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * where {@code sObj} is a {@code Short} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * {@code sObj.shortValue() == s}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * @param s   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   784
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   785
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   786
     *              field is either inaccessible or final.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    public void setShort(Object obj, short s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        getFieldAccessor(obj).setShort(obj, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * Sets the value of a field as an {@code int} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * {@code set(obj, iObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * where {@code iObj} is a {@code Integer} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * {@code iObj.intValue() == i}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * @param i   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   814
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   815
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   816
     *              field is either inaccessible or final.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    public void setInt(Object obj, int i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        getFieldAccessor(obj).setInt(obj, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * Sets the value of a field as a {@code long} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * {@code set(obj, lObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * where {@code lObj} is a {@code Long} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * {@code lObj.longValue() == l}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * @param l   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   844
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   845
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   846
     *              field is either inaccessible or final.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    public void setLong(Object obj, long l)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        getFieldAccessor(obj).setLong(obj, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * Sets the value of a field as a {@code float} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * {@code set(obj, fObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * where {@code fObj} is a {@code Float} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * {@code fObj.floatValue() == f}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * @param f   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   874
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   875
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   876
     *              field is either inaccessible or final.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    public void setFloat(Object obj, float f)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        getFieldAccessor(obj).setFloat(obj, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * Sets the value of a field as a {@code double} on the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * This method is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * {@code set(obj, dObj)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * where {@code dObj} is a {@code Double} object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * {@code dObj.doubleValue() == d}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * @param obj the object whose field should be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * @param d   the new value for the field of {@code obj}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * being modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     *
9022
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   904
     * @exception IllegalAccessException    if this {@code Field} object
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   905
     *              is enforcing Java language access control and the underlying
b2e8758b10fd 6543593: (reflect) Clarify private final field mutability
darcy
parents: 5506
diff changeset
   906
     *              field is either inaccessible or final.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * @exception IllegalArgumentException  if the specified object is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     *              instance of the class or interface declaring the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     *              field (or a subclass or implementor thereof),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     *              or if an unwrapping conversion fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * @exception NullPointerException      if the specified object is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     *              and the field is an instance field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * @exception ExceptionInInitializerError if the initialization provoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     *              by this method fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * @see       Field#set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    public void setDouble(Object obj, double d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        throws IllegalArgumentException, IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        getFieldAccessor(obj).setDouble(obj, d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    // Convenience routine which performs security checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    private FieldAccessor getFieldAccessor(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        throws IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        doSecurityCheck(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        boolean ov = override;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        FieldAccessor a = (ov)? overrideFieldAccessor : fieldAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        return (a != null)? a : acquireFieldAccessor(ov);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    // NOTE that there is no synchronization used here. It is correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    // (though not efficient) to generate more than one FieldAccessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    // for a given Field. However, avoiding synchronization will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    // probably make the implementation more scalable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    private FieldAccessor acquireFieldAccessor(boolean overrideFinalCheck) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        // First check to see if one has been created yet, and take it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        // if so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        FieldAccessor tmp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        if (root != null) tmp = root.getFieldAccessor(overrideFinalCheck);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        if (tmp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            if (overrideFinalCheck)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                overrideFieldAccessor = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                fieldAccessor = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            // Otherwise fabricate one and propagate it up to the root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            tmp = reflectionFactory.newFieldAccessor(this, overrideFinalCheck);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            setFieldAccessor(tmp, overrideFinalCheck);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        }
9029
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   952
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        return tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    // Returns FieldAccessor for this Field object, not looking up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    // the chain to the root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    private FieldAccessor getFieldAccessor(boolean overrideFinalCheck) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        return (overrideFinalCheck)? overrideFieldAccessor : fieldAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    // Sets the FieldAccessor for this Field object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    // (recursively) its root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    private void setFieldAccessor(FieldAccessor accessor, boolean overrideFinalCheck) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        if (overrideFinalCheck)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            overrideFieldAccessor = accessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            fieldAccessor = accessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        // Propagate up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        if (root != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            root.setFieldAccessor(accessor, overrideFinalCheck);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    // NOTE: be very careful if you change the stack depth of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    // routine. The depth of the "getCallerClass" call is hardwired so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    // that the compiler can have an easier time if this gets inlined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    private void doSecurityCheck(Object obj) throws IllegalAccessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        if (!override) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2174
diff changeset
   981
                Class<?> caller = Reflection.getCallerClass(4);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
9029
e92fcf58f684 6565585: Remove critical section in Method.invoke, Constructor.newInstance, Field.getFieldAccessor improving performance
mduigou
parents: 9022
diff changeset
   983
                checkAccess(caller, clazz, obj, modifiers);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * Utility routine to paper over array type names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     */
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2174
diff changeset
   991
    static String getTypeName(Class<?> type) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        if (type.isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            try {
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2174
diff changeset
   994
                Class<?> cl = type;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                int dimensions = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                while (cl.isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                    dimensions++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                    cl = cl.getComponentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                StringBuffer sb = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                sb.append(cl.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                for (int i = 0; i < dimensions; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                    sb.append("[]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            } catch (Throwable e) { /*FALLTHRU*/ }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        return type.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     */
10342
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 9266
diff changeset
  1015
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        if (annotationClass == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        return (T) declaredAnnotations().get(annotationClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    public Annotation[] getDeclaredAnnotations()  {
2174
0ffce164e4a4 6799230: Lazily load java.lang.annotation.Annotation class
mchung
parents: 2
diff changeset
  1027
        return AnnotationParser.toArray(declaredAnnotations());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2174
diff changeset
  1030
    private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2174
diff changeset
  1032
    private synchronized  Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        if (declaredAnnotations == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            declaredAnnotations = AnnotationParser.parseAnnotations(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                annotations, sun.misc.SharedSecrets.getJavaLangAccess().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                getConstantPool(getDeclaringClass()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                getDeclaringClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        return declaredAnnotations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
}