- Type Parameters:
T- the modeled type; often parameterized
Type that embodies Gafter's gadget.
To use this class, create a new instance of an anonymous
subclass of it, and then call type() on it. For
example:
// type will be a ParameterizedType whose rawType is List.class and // whose sole type argument is String.class Type type = new TypeToken<List<String>>() {}.type(); assert type instanceof ParameterizedType; assert ((ParameterizedType)type).getRawType() == List.class; assert ((ParameterizedType)type).getActualTypeArguments()[0] == String.class;
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanfinal Class<?> erase()Returns the type erasure of thisTypeToken's modeledType, ornullif erasing theTypewould result in a non-Classerasure (in which case the erasure is simply theTypeitself), or if an erasure cannot be determined.inthashCode()toString()final Typetype()
-
Constructor Details
-
TypeToken
protected TypeToken()Creates a newTypeToken.
-
-
Method Details
-
type
Returns theTypemodeled by thisTypeToken.This method never returns
null.This method produces a determinate value.
This method is idempotent.
This method is safe for concurrent use by multiple threads.
-
erase
Returns the type erasure of thisTypeToken's modeledType, ornullif erasing theTypewould result in a non-Classerasure (in which case the erasure is simply theTypeitself), or if an erasure cannot be determined.This method never returns
null.This method produces a determinate value.
This method is idempotent.
This method is safe for concurrent use by multiple threads.
- Returns:
- the type erasure of this
TypeToken's modeledType, ornullif erasing theTypewould result in a non-Classerasure, or if an erasure cannot be determined
-
hashCode
public int hashCode()Returns a hashcode for thisTypeTokencomputed from theTypeit models.This method produces a determinate value.
This method is idempotent.
This method is safe for concurrent use by multiple threads.
-
equals
Returnstrueif the suppliedObjectis equal to thisTypeToken.This method returns
trueif the suppliedObject's class is thisTypeToken's class and if its modeledTypeis equal to thisTypeToken's modeledType.This method produces a determinate value.
This method is idempotent.
This method is safe for concurrent use by multiple threads.
-
toString
Returns aStringrepresentation of thisTypeToken.This method returns a value equal to that returned by
this.type().getTypeName().This method never returns
null.This method produces a determinate value.
This method is idempotent.
This method is safe for concurrent use by multiple threads.
-