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