FieldAttributes (Gson 2.3 API)
Date: 2014-08-11

com.google.gson

## Class FieldAttributes

- java.lang.Object
- - com.google.gson.FieldAttributes

-     public final class FieldAttributes
      extends Object

  A data object that stores attributes of a field.

  This class is immutable; therefore, it can be safely shared across threads.

  Since:
    1.4
  Author:
    Inderjeet Singh, Joel Leitch

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FieldAttributes(Field f)` Constructs a Field Attributes object from the `f`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `<T extends Annotation> T` | `getAnnotation(Class<T> annotation)` Return the `T` annotation object from this field if it exist; otherwise returns `null`.
    `Collection<Annotation>` | `getAnnotations()` Return the annotations that are present on this field.
    `Class<?>` | `getDeclaredClass()` Returns the `Class` object that was declared for this field.
    `Type` | `getDeclaredType()` For example, assume the following class definition:
         public class Foo {
           private String bar;
           private List<String> red;
         }

         Type listParmeterizedType = new TypeToken<List<String>>() {}.getType();
    `Class<?>` | `getDeclaringClass()`
    `String` | `getName()`
    `boolean` | `hasModifier(int modifier)` Returns `true` if the field is defined with the `modifier`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### FieldAttributes

          public FieldAttributes(Field f)

      Constructs a Field Attributes object from the `f`.
      Parameters:
        `f` - the field to pull attributes from

  - ### Method Detail

    - #### getDeclaringClass

          public Class<?> getDeclaringClass()

      Returns:
        the declaring class that contains this field

    - #### getName

          public String getName()

      Returns:
        the name of the field

    - #### getDeclaredType

          public Type getDeclaredType()

      For example, assume the following class definition:

           public class Foo {
             private String bar;
             private List<String> red;
           }

           Type listParmeterizedType = new TypeToken<List<String>>() {}.getType();

      This method would return `String.class` for the `bar` field and `listParameterizedType` for the `red` field.

      Returns:
        the specific type declared for this field

    - #### getDeclaredClass

          public Class<?> getDeclaredClass()

      Returns the `Class` object that was declared for this field.

      For example, assume the following class definition:

           public class Foo {
             private String bar;
             private List<String> red;
           }

      This method would return `String.class` for the `bar` field and `List.class` for the `red` field.

      Returns:
        the specific class object that was declared for the field

    - #### getAnnotation

          public <T extends Annotation> T getAnnotation(Class<T> annotation)

      Return the `T` annotation object from this field if it exist; otherwise returns `null`.
      Parameters:
        `annotation` - the class of the annotation that will be retrieved
      Returns:
        the annotation instance if it is bound to the field; otherwise `null`

    - #### getAnnotations

          public Collection<Annotation> getAnnotations()

      Return the annotations that are present on this field.
      Returns:
        an array of all the annotations set on the field
      Since:
        1.4

    - #### hasModifier

          public boolean hasModifier(int modifier)

      Returns `true` if the field is defined with the `modifier`.

      This method is meant to be called as:

           boolean hasPublicModifier = fieldAttribute.hasModifier(java.lang.reflect.Modifier.PUBLIC);

      See Also:
        `Modifier`

Copyright © 2008–2014 Google, Inc.. All rights reserved.