| /* |
| * Licensed to the Apache Software Foundation (ASF) under one or more |
| * contributor license agreements. See the NOTICE file distributed with |
| * this work for additional information regarding copyright ownership. |
| * The ASF licenses this file to You under the Apache License, Version 2.0 |
| * (the "License"); you may not use this file except in compliance with |
| * the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package java.lang.reflect; |
| |
| /** |
| * This class represents a field. Information about the field can be accessed, |
| * and the field's value can be accessed dynamically. |
| */ |
| public final class Field extends AccessibleObject implements Member { |
| |
| /* |
| * This class must be implemented by the VM vendor. |
| */ |
| |
| /** |
| * Prevent this class from being instantiated |
| */ |
| private Field(){ |
| //do nothing |
| } |
| |
| /** |
| * Returns the field's signature in non-printable form. This is called |
| * (only) from IO native code and needed for deriving the serialVersionUID |
| * of the class |
| * |
| * @return the field's signature. |
| */ |
| native String getSignature(); |
| |
| /** |
| * Indicates whether or not this field is synthetic. |
| * |
| * @return {@code true} if this field is synthetic, {@code false} otherwise |
| */ |
| public boolean isSynthetic() { |
| return false; |
| } |
| |
| /** |
| * Returns the string representation of this field, including the field's |
| * generic type. |
| * |
| * @return the string representation of this field |
| * @since 1.5 |
| */ |
| public String toGenericString() { |
| return null; |
| } |
| |
| /** |
| * Indicates whether or not this field is an enumeration constant. |
| * |
| * @return {@code true} if this field is an enumeration constant, {@code |
| * false} otherwise |
| * @since 1.5 |
| */ |
| public boolean isEnumConstant() { |
| return false; |
| } |
| |
| /** |
| * Returns the generic type of this field. |
| * |
| * @return the generic type |
| * @throws GenericSignatureFormatError |
| * if the generic field signature is invalid |
| * @throws TypeNotPresentException |
| * if the generic type points to a missing type |
| * @throws MalformedParameterizedTypeException |
| * if the generic type points to a type that cannot be |
| * instantiated for some reason |
| * @since 1.5 |
| */ |
| public Type getGenericType() { |
| return null; |
| } |
| |
| /** |
| * Indicates whether or not the specified {@code object} is equal to this |
| * field. To be equal, the specified object must be an instance of |
| * {@code Field} with the same declaring class, type and name as this field. |
| * |
| * @param object |
| * the object to compare |
| * @return {@code true} if the specified object is equal to this method, |
| * {@code false} otherwise |
| * @see #hashCode |
| */ |
| @Override |
| public boolean equals(Object object) { |
| return false; |
| } |
| |
| /** |
| * Returns the value of the field in the specified object. This reproduces |
| * the effect of {@code object.fieldName} |
| * <p> |
| * If the type of this field is a primitive type, the field value is |
| * automatically wrapped. |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is null, a NullPointerException is thrown. If |
| * the object is not an instance of the declaring class of the method, an |
| * IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @return the field value, possibly wrapped |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native Object get(Object object) throws IllegalAccessException, |
| IllegalArgumentException; |
| |
| /** |
| * Returns the value of the field in the specified object as a {@code |
| * boolean}. This reproduces the effect of {@code object.fieldName} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @return the field value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native boolean getBoolean(Object object) |
| throws IllegalAccessException, IllegalArgumentException; |
| |
| /** |
| * Returns the value of the field in the specified object as a {@code byte}. |
| * This reproduces the effect of {@code object.fieldName} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @return the field value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native byte getByte(Object object) throws IllegalAccessException, |
| IllegalArgumentException; |
| |
| /** |
| * Returns the value of the field in the specified object as a {@code char}. |
| * This reproduces the effect of {@code object.fieldName} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @return the field value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native char getChar(Object object) throws IllegalAccessException, |
| IllegalArgumentException; |
| |
| /** |
| * Returns the class that declares this field. |
| * |
| * @return the declaring class |
| */ |
| public Class<?> getDeclaringClass() { |
| return null; |
| } |
| |
| /** |
| * Returns the value of the field in the specified object as a {@code |
| * double}. This reproduces the effect of {@code object.fieldName} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @return the field value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native double getDouble(Object object) |
| throws IllegalAccessException, IllegalArgumentException; |
| |
| /** |
| * Returns the value of the field in the specified object as a {@code float}. |
| * This reproduces the effect of {@code object.fieldName} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @return the field value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native float getFloat(Object object) throws IllegalAccessException, |
| IllegalArgumentException; |
| |
| /** |
| * Returns the value of the field in the specified object as an {@code int}. |
| * This reproduces the effect of {@code object.fieldName} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @return the field value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native int getInt(Object object) throws IllegalAccessException, |
| IllegalArgumentException; |
| |
| /** |
| * Returns the value of the field in the specified object as a {@code long}. |
| * This reproduces the effect of {@code object.fieldName} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @return the field value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native long getLong(Object object) throws IllegalAccessException, |
| IllegalArgumentException; |
| |
| /** |
| * Returns the modifiers for this field. The {@link Modifier} class should |
| * be used to decode the result. |
| * |
| * @return the modifiers for this field |
| * @see Modifier |
| */ |
| public native int getModifiers(); |
| |
| /** |
| * Returns the name of this field. |
| * |
| * @return the name of this field |
| */ |
| public String getName() { |
| return null; |
| } |
| |
| /** |
| * Returns the value of the field in the specified object as a {@code short} |
| * . This reproduces the effect of {@code object.fieldName} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @return the field value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native short getShort(Object object) throws IllegalAccessException, |
| IllegalArgumentException; |
| |
| /** |
| * Return the {@link Class} associated with the type of this field. |
| * |
| * @return the type of this field |
| */ |
| public Class<?> getType() { |
| return null; |
| } |
| |
| /** |
| * Returns an integer hash code for this field. Objects which are equal |
| * return the same value for this method. |
| * <p> |
| * The hash code for a Field is the exclusive-or combination of the hash |
| * code of the field's name and the hash code of the name of its declaring |
| * class. |
| * |
| * @return the hash code for this field |
| * @see #equals |
| */ |
| @Override |
| public int hashCode() { |
| return 0; |
| } |
| |
| /** |
| * Sets the value of the field in the specified object to the value. This |
| * reproduces the effect of {@code object.fieldName = value} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * <p> |
| * If the field type is a primitive type, the value is automatically |
| * unwrapped. If the unwrap fails, an IllegalArgumentException is thrown. If |
| * the value cannot be converted to the field type via a widening |
| * conversion, an IllegalArgumentException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @param value |
| * the new value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native void set(Object object, Object value) |
| throws IllegalAccessException, IllegalArgumentException; |
| |
| /** |
| * Sets the value of the field in the specified object to the {@code |
| * boolean} value. This reproduces the effect of {@code object.fieldName = |
| * value} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * <p> |
| * If the value cannot be converted to the field type via a widening |
| * conversion, an IllegalArgumentException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @param value |
| * the new value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native void setBoolean(Object object, boolean value) |
| throws IllegalAccessException, IllegalArgumentException; |
| |
| /** |
| * Sets the value of the field in the specified object to the {@code byte} |
| * value. This reproduces the effect of {@code object.fieldName = value} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * <p> |
| * If the value cannot be converted to the field type via a widening |
| * conversion, an IllegalArgumentException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @param value |
| * the new value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native void setByte(Object object, byte value) |
| throws IllegalAccessException, IllegalArgumentException; |
| |
| /** |
| * Sets the value of the field in the specified object to the {@code char} |
| * value. This reproduces the effect of {@code object.fieldName = value} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * <p> |
| * If the value cannot be converted to the field type via a widening |
| * conversion, an IllegalArgumentException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @param value |
| * the new value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native void setChar(Object object, char value) |
| throws IllegalAccessException, IllegalArgumentException; |
| |
| /** |
| * Sets the value of the field in the specified object to the {@code double} |
| * value. This reproduces the effect of {@code object.fieldName = value} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * <p> |
| * If the value cannot be converted to the field type via a widening |
| * conversion, an IllegalArgumentException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @param value |
| * the new value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native void setDouble(Object object, double value) |
| throws IllegalAccessException, IllegalArgumentException; |
| |
| /** |
| * Sets the value of the field in the specified object to the {@code float} |
| * value. This reproduces the effect of {@code object.fieldName = value} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * <p> |
| * If the value cannot be converted to the field type via a widening |
| * conversion, an IllegalArgumentException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @param value |
| * the new value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native void setFloat(Object object, float value) |
| throws IllegalAccessException, IllegalArgumentException; |
| |
| /** |
| * Set the value of the field in the specified object to the {@code int} |
| * value. This reproduces the effect of {@code object.fieldName = value} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * <p> |
| * If the value cannot be converted to the field type via a widening |
| * conversion, an IllegalArgumentException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @param value |
| * the new value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native void setInt(Object object, int value) |
| throws IllegalAccessException, IllegalArgumentException; |
| |
| /** |
| * Sets the value of the field in the specified object to the {@code long} |
| * value. This reproduces the effect of {@code object.fieldName = value} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * <p> |
| * If the value cannot be converted to the field type via a widening |
| * conversion, an IllegalArgumentException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @param value |
| * the new value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native void setLong(Object object, long value) |
| throws IllegalAccessException, IllegalArgumentException; |
| |
| /** |
| * Sets the value of the field in the specified object to the {@code short} |
| * value. This reproduces the effect of {@code object.fieldName = value} |
| * <p> |
| * If this field is static, the object argument is ignored. |
| * Otherwise, if the object is {@code null}, a NullPointerException is |
| * thrown. If the object is not an instance of the declaring class of the |
| * method, an IllegalArgumentException is thrown. |
| * <p> |
| * If this Field object is enforcing access control (see AccessibleObject) |
| * and this field is not accessible from the current context, an |
| * IllegalAccessException is thrown. |
| * <p> |
| * If the value cannot be converted to the field type via a widening |
| * conversion, an IllegalArgumentException is thrown. |
| * |
| * @param object |
| * the object to access |
| * @param value |
| * the new value |
| * @throws NullPointerException |
| * if the object is {@code null} and the field is non-static |
| * @throws IllegalArgumentException |
| * if the object is not compatible with the declaring class |
| * @throws IllegalAccessException |
| * if this field is not accessible |
| */ |
| public native void setShort(Object object, short value) |
| throws IllegalAccessException, IllegalArgumentException; |
| |
| /** |
| * Returns a string containing a concise, human-readable description of this |
| * field. |
| * <p> |
| * The format of the string is: |
| * <ol> |
| * <li>modifiers (if any) |
| * <li>type |
| * <li>declaring class name |
| * <li>'.' |
| * <li>field name |
| * </ol> |
| * <p> |
| * For example: {@code public static java.io.InputStream |
| * java.lang.System.in} |
| * |
| * @return a printable representation for this field |
| */ |
| @Override |
| public String toString() { |
| return null; |
| } |
| } |