Top Description Fields Constructors Methods
com.google.gson

public final Class FieldAttributes

extends Object
Class Inheritance
Imports
java.lang.annotation.Annotation, java.lang.reflect.Field, .Type, java.util.Arrays, .Collection, .Objects

A data object that stores attributes of a field.

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

Authors
Inderjeet Singh, Joel Leitch
Since
1.4

Field Summary

Modifier and TypeField and Description
private final Field

Constructor Summary

AccessConstructor and Description
public
FieldAttributes(Field
the field to pull attributes from
f
)

Constructs a Field Attributes object from the f.

Method Summary

Modifier and TypeMethod and Description
public <T extends Annotation> T

Returns:

the annotation instance if it is bound to the field; otherwise null
getAnnotation
(Class<T>
the class of the annotation that will be retrieved
annotation
)

Returns the T annotation object from this field if it exists; otherwise returns null.

public Collection<Annotation>

Returns:

an array of all the annotations set on the field
getAnnotations
()

Returns the annotations that are present on this field.

public Class<?>

Returns:

the specific class object that was declared for the field
getDeclaredClass
()

Returns the Class object that was declared for this field.

public Type

Returns:

the specific type declared for this field
getDeclaredType
()

Returns the declared generic type of the field.

public Class<?>

Returns:

the declaring class that contains this field
getDeclaringClass
()

Gets the declaring Class that contains this field

public String

Returns:

the name of the field
getName
()

Gets the name of the field

public boolean
hasModifier(int modifier)

Returns true if the field is defined with the modifier.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

fieldback to summary
private final Field field

Constructor Detail

FieldAttributesback to summary
public FieldAttributes(Field f)

Constructs a Field Attributes object from the f.

Parameters
f:Field

the field to pull attributes from

Method Detail

getAnnotationback to summary
public <T extends Annotation> T getAnnotation(Class<T> annotation)

Returns the T annotation object from this field if it exists; otherwise returns null.

Parameters
annotation:Class<T>

the class of the annotation that will be retrieved

Returns:T

the annotation instance if it is bound to the field; otherwise null

getAnnotationsback to summary
public Collection<Annotation> getAnnotations()

Returns the annotations that are present on this field.

Returns:Collection<Annotation>

an array of all the annotations set on the field

Since
1.4
getDeclaredClassback to summary
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:Class<?>

the specific class object that was declared for the field

getDeclaredTypeback to summary
public Type getDeclaredType()

Returns the declared generic type of the field.

For example, assume the following class definition:

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

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

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

Returns:Type

the specific type declared for this field

getDeclaringClassback to summary
public Class<?> getDeclaringClass()

Gets the declaring Class that contains this field

Returns:Class<?>

the declaring class that contains this field

getNameback to summary
public String getName()

Gets the name of the field

Returns:String

the name of the field

hasModifierback to summary
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
java.lang.reflect.Modifier
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override