Method or a Constructor. Convenience API is provided to
make common reflective operation easier to deal with, such as isPublic, getParameters etc.
In addition to convenience methods, TypeToken#method and TypeToken#constructor
will resolve the type parameters of the method or constructor in the context of the owner type,
which may be a subtype of the declaring class. For example:
Method getMethod = List.class.getMethod("get", int.class);
Invokable<List<String>, ?> invokable = new TypeToken<List<String>>() {}.method(getMethod);
assertEquals(TypeToken.of(String.class), invokable.getReturnType()); // Not Object.class!
assertEquals(new TypeToken<List<String>>() {}, invokable.getOwnerType());
Note
earlier versions of this class inherited from AccessibleObject and GenericDeclaration. Since version 31.0 that is no longer
the case. However, most methods from those types are present with the same signature in this
class.
AccessibleObject or GenericDeclaration since
31.0)
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| private final AccessibleObject | |
| private static final boolean | |
| private final Member |
| Access | Constructor and Description |
|---|---|
| pack-priv <M extends AccessibleObject & Member> |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | equals(Object
the reference object with which to compare. obj)Overrides java. |
| public static Invokable | |
| public static <T> Invokable | |
| pack-priv abstract AnnotatedType[] | |
| public abstract AnnotatedType | |
| public final <A extends Annotation> A | getAnnotation(Class<A>
the Class object corresponding to the
annotation type annotationClass)Implements java. |
| public final Annotation[] | getAnnotations()
Implements java. |
| public final Annotation[] | getDeclaredAnnotations()
Implements java. |
| public final Class | getDeclaringClass()
Implements java. |
| public final ImmutableList | |
| pack-priv abstract Type[] | |
| pack-priv abstract Type[] | |
| pack-priv abstract Type | |
| public final int | getModifiers()
Implements java. |
| public final String | getName()
Implements java. |
| public TypeToken | |
| pack-priv abstract Annotation[][] | |
| public final ImmutableList | |
| public final TypeToken | |
| public abstract TypeVariable | |
| public int | |
| private static boolean | |
| public final R | |
| pack-priv abstract Object | |
| public final boolean | |
| public final boolean | |
| public final boolean | isAnnotationPresent(Class<? extends Annotation>
the Class object corresponding to the
annotation type annotationClass)Overrides default java. |
| public final boolean | |
| public final boolean | |
| public abstract boolean | |
| public final boolean | |
| public final boolean | |
| public final boolean | |
| public final boolean | |
| public final boolean | |
| public final boolean | |
| public final boolean | isSynthetic()
Implements java. true if this member was introduced by
the compiler; returns false otherwise.
|
| pack-priv final boolean | |
| public abstract boolean | |
| pack-priv final boolean | |
| public final <R1 extends R> Invokable | |
| public final <R1 extends R> Invokable | |
| public final void | |
| public String | |
| public final boolean |
| accessibleObject | back to summary |
|---|---|
| private final AccessibleObject accessibleObject | |
| ANNOTATED_TYPE_EXISTS | back to summary |
|---|---|
| private static final boolean ANNOTATED_TYPE_EXISTS | |
| member | back to summary |
|---|---|
| private final Member member | |
| Invokable | back to summary |
|---|---|
| pack-priv <M extends AccessibleObject & Member> Invokable(M member) | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| from | back to summary |
|---|---|
| public static Invokable Returns | |
| from | back to summary |
|---|---|
| public static <T> Invokable Returns | |
| getAnnotatedParameterTypes | back to summary |
|---|---|
pack-priv abstract AnnotatedType[] getAnnotatedParameterTypes()
| |
| getAnnotatedReturnType | back to summary |
|---|---|
| public abstract AnnotatedType getAnnotatedReturnType() Returns the This method will fail if run under an Android VM.
| |
| getAnnotation | back to summary |
|---|---|
| public final <A extends Annotation> A getAnnotation(Class<A> annotationClass) Implements java. Doc from java. Returns this element's annotation for the specified type if such an annotation is present, else null.
| |
| getAnnotations | back to summary |
|---|---|
| public final Annotation[] getAnnotations() Implements java. Doc from java. Returns annotations that are present on this element. If there are no annotations present on this element, the return value is an array of length 0. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.
| |
| getDeclaredAnnotations | back to summary |
|---|---|
| public final Annotation[] getDeclaredAnnotations() Implements java. Doc from java. Returns annotations that are directly present on this element. This method ignores inherited annotations. If there are no annotations directly present on this element, the return value is an array of length 0. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.
| |
| getDeclaringClass | back to summary |
|---|---|
| public final Class Implements java. Doc from java. Returns the Class object representing the class or interface that declares the member or constructor represented by this Member.
| |
| getExceptionTypes | back to summary |
|---|---|
| public final ImmutableList Returns all declared exception types of this | |
| getGenericExceptionTypes | back to summary |
|---|---|
| pack-priv abstract Type[] getGenericExceptionTypes() This should never return a type that's not a subtype of Throwable. | |
| getGenericParameterTypes | back to summary |
|---|---|
| pack-priv abstract Type[] getGenericParameterTypes() | |
| getGenericReturnType | back to summary |
|---|---|
| pack-priv abstract Type getGenericReturnType() | |
| getModifiers | back to summary |
|---|---|
| public final int getModifiers() Implements java. Doc from java. Returns the Java language modifiers for the member or constructor represented by this Member, as an integer. The Modifier class should be used to decode the modifiers in the integer.
| |
| getName | back to summary |
|---|---|
| public final String getName() Implements java. Doc from java. Returns the simple name of the underlying member or constructor represented by this Member. | |
| getOwnerType | back to summary |
|---|---|
| public TypeToken Returns the type of
| |
| getParameterAnnotations | back to summary |
|---|---|
| pack-priv abstract Annotation[][] getParameterAnnotations() | |
| getParameters | back to summary |
|---|---|
| public final ImmutableList Returns all declared parameters of this
| |
| getReturnType | back to summary |
|---|---|
| public final TypeToken Returns the return type of this
| |
| getTypeParameters | back to summary |
|---|---|
| public abstract TypeVariable See | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| initAnnotatedTypeExists | back to summary |
|---|---|
| private static boolean initAnnotatedTypeExists() | |
| invoke | back to summary |
|---|---|
| public final R invoke(T receiver, @Nullable Object... args) throws InvocationTargetException, IllegalAccessException Invokes with
| |
| invokeInternal | back to summary |
|---|---|
pack-priv abstract Object invokeInternal(Object receiver, @Nullable Object[] args) throws InvocationTargetException, IllegalAccessException
| |
| isAbstract | back to summary |
|---|---|
| public final boolean isAbstract() Returns true if the method is abstract. | |
| isAccessible | back to summary |
|---|---|
| public final boolean isAccessible() | |
| isAnnotationPresent | back to summary |
|---|---|
| public final boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) Overrides default java. Doc from java. Returns true if an annotation for the specified type is present on this element, else false. This method is designed primarily for convenient access to marker annotations. The truth value returned by this method is equivalent to:
| |
| isFinal | back to summary |
|---|---|
| public final boolean isFinal() Returns Note that a method may still be effectively "final", or non-overridable when it has no
| |
| isNative | back to summary |
|---|---|
| public final boolean isNative() Returns true if the element is native. | |
| isOverridable | back to summary |
|---|---|
| public abstract boolean isOverridable() Returns | |
| isPackagePrivate | back to summary |
|---|---|
| public final boolean isPackagePrivate() Returns true if the element is package-private. | |
| isPrivate | back to summary |
|---|---|
| public final boolean isPrivate() Returns true if the element is private. | |
| isProtected | back to summary |
|---|---|
| public final boolean isProtected() Returns true if the element is protected. | |
| isPublic | back to summary |
|---|---|
| public final boolean isPublic() Returns true if the element is public. | |
| isStatic | back to summary |
|---|---|
| public final boolean isStatic() Returns true if the element is static. | |
| isSynchronized | back to summary |
|---|---|
| public final boolean isSynchronized() Returns true if the method is synchronized. | |
| isSynthetic | back to summary |
|---|---|
| public final boolean isSynthetic() Implements java. Doc from java. Returns
| |
| isTransient | back to summary |
|---|---|
| pack-priv final boolean isTransient() Returns true if the field is transient. | |
| isVarArgs | back to summary |
|---|---|
| public abstract boolean isVarArgs() Returns | |
| isVolatile | back to summary |
|---|---|
| pack-priv final boolean isVolatile() Returns true if the field is volatile. | |
| returning | back to summary |
|---|---|
| public final <R1 extends R> Invokable Explicitly specifies the return type of this
| |
| returning | back to summary |
|---|---|
| public final <R1 extends R> Invokable Explicitly specifies the return type of this | |
| setAccessible | back to summary |
|---|---|
| public final void setAccessible(boolean flag) See | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| trySetAccessible | back to summary |
|---|---|
| public final boolean trySetAccessible() | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final Constructor |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| constructor | back to summary |
|---|---|
| pack-priv final Constructor<?> constructor | |
| ConstructorInvokable | back to summary |
|---|---|
| pack-priv ConstructorInvokable(Constructor<?> constructor) | |
| getAnnotatedParameterTypes | back to summary |
|---|---|
| pack-priv AnnotatedType[] getAnnotatedParameterTypes() Implements abstract com.
| |
| getAnnotatedReturnType | back to summary |
|---|---|
| public AnnotatedType getAnnotatedReturnType() Implements abstract com. Doc from com. Returns the This method will fail if run under an Android VM.
| |
| getGenericExceptionTypes | back to summary |
|---|---|
| pack-priv Type[] getGenericExceptionTypes() Implements abstract com. Doc from com. This should never return a type that's not a subtype of Throwable.
| |
| getGenericParameterTypes | back to summary |
|---|---|
| pack-priv Type[] getGenericParameterTypes() Implements abstract com.
| |
| getGenericReturnType | back to summary |
|---|---|
| pack-priv Type getGenericReturnType() Implements abstract com. If the class is parameterized, such as
| |
| getParameterAnnotations | back to summary |
|---|---|
| pack-priv final Annotation[][] getParameterAnnotations() Implements abstract com.
| |
| getTypeParameters | back to summary |
|---|---|
| public final TypeVariable Implements abstract com. Doc from com. See
| |
| invokeInternal | back to summary |
|---|---|
pack-priv final Object invokeInternal(Object receiver, @Nullable Object[] args) throws InvocationTargetException, IllegalAccessException
| |
| isOverridable | back to summary |
|---|---|
| public final boolean isOverridable() Implements abstract com. Doc from com. Returns
| |
| isVarArgs | back to summary |
|---|---|
| public final boolean isVarArgs() Implements abstract com. Doc from com. Returns
| |
| mayNeedHiddenThis | back to summary |
|---|---|
| private boolean mayNeedHiddenThis() | |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| method | back to summary |
|---|---|
| pack-priv final Method method | |
| MethodInvokable | back to summary |
|---|---|
| pack-priv MethodInvokable(Method method) | |
| getAnnotatedParameterTypes | back to summary |
|---|---|
| pack-priv AnnotatedType[] getAnnotatedParameterTypes() Implements abstract com.
| |
| getAnnotatedReturnType | back to summary |
|---|---|
| public AnnotatedType getAnnotatedReturnType() Implements abstract com. Doc from com. Returns the This method will fail if run under an Android VM.
| |
| getGenericExceptionTypes | back to summary |
|---|---|
| pack-priv Type[] getGenericExceptionTypes() Implements abstract com. Doc from com. This should never return a type that's not a subtype of Throwable.
| |
| getGenericParameterTypes | back to summary |
|---|---|
| pack-priv Type[] getGenericParameterTypes() Implements abstract com.
| |
| getGenericReturnType | back to summary |
|---|---|
| pack-priv Type getGenericReturnType() Implements abstract com.
| |
| getParameterAnnotations | back to summary |
|---|---|
| pack-priv final Annotation[][] getParameterAnnotations() Implements abstract com.
| |
| getTypeParameters | back to summary |
|---|---|
| public final TypeVariable Implements abstract com. Doc from com. See
| |
| invokeInternal | back to summary |
|---|---|
pack-priv final Object invokeInternal(Object receiver, @Nullable Object[] args) throws InvocationTargetException, IllegalAccessException
| |
| isOverridable | back to summary |
|---|---|
| public final boolean isOverridable() Implements abstract com. Doc from com. Returns
| |
| isVarArgs | back to summary |
|---|---|
| public final boolean isVarArgs() Implements abstract com. Doc from com. Returns
| |