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