Package com.google.common.reflect
Class Invokable<T,R>
java.lang.Object
java.lang.reflect.AccessibleObject
com.google.common.reflect.Invokable<T,R>
- Type Parameters:
T- the type that owns this method or constructor.R- the return type of (or supertype thereof) the method or the declaring type of the constructor.
- All Implemented Interfaces:
AnnotatedElement,GenericDeclaration,Member
@Beta
@Deprecated(since="2022-12-01")
public abstract class Invokable<T,R>
extends AccessibleObject
implements GenericDeclaration
Deprecated.
The Google Guava Core Libraries are deprecated and will not be part of the AEM SDK after April 2023
Wrapper around either a
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(java.lang.reflect.Method) and TypeToken.constructor(java.lang.reflect.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());- Since:
- 14.0
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionbooleanDeprecated.static <T> Invokable<T, T> from(Constructor<T> constructor) Deprecated.ReturnsInvokableofconstructor.Deprecated.ReturnsInvokableofmethod.final <A extends Annotation>
AgetAnnotation(Class<A> annotationClass) Deprecated.final Annotation[]Deprecated.final Annotation[]Deprecated.Deprecated.final ImmutableList<TypeToken<? extends Throwable>> Deprecated.Returns all declared exception types of thisInvokable.final intDeprecated.final StringgetName()Deprecated.Deprecated.Returns the type ofT.final ImmutableList<Parameter> Deprecated.Returns all declared parameters of thisInvokable.Deprecated.Returns the return type of thisInvokable.inthashCode()Deprecated.final RDeprecated.Invokes withreceiveras 'this' andargspassed to the underlying method and returns the return value; or calls the underlying constructor withargsand returns the constructed instance.final booleanDeprecated.Returns true if the method is abstract.final booleanDeprecated.final booleanisAnnotationPresent(Class<? extends Annotation> annotationClass) Deprecated.final booleanisFinal()Deprecated.Returnstrueif this method is final, perModifier.isFinal(getModifiers()).final booleanisNative()Deprecated.Returns true if the element is native.abstract booleanDeprecated.Returnstrueif this is an overridable method.final booleanDeprecated.Returns true if the element is package-private.final booleanDeprecated.Returns true if the element is private.final booleanDeprecated.Returns true if the element is protected.final booleanisPublic()Deprecated.Returns true if the element is public.final booleanisStatic()Deprecated.Returns true if the element is static.final booleanDeprecated.Returns true if the method is synchronized.final booleanDeprecated.abstract booleanDeprecated.Returnstrueif this was declared to take a variable number of arguments.Deprecated.Explicitly specifies the return type of thisInvokable.Deprecated.Explicitly specifies the return type of thisInvokable.final voidsetAccessible(boolean flag) Deprecated.toString()Deprecated.Methods inherited from class java.lang.reflect.AccessibleObject
canAccess, getAnnotationsByType, getDeclaredAnnotation, getDeclaredAnnotationsByType, setAccessible, trySetAccessibleMethods inherited from interface java.lang.reflect.AnnotatedElement
getAnnotation, getAnnotations, getAnnotationsByType, getDeclaredAnnotation, getDeclaredAnnotations, getDeclaredAnnotationsByType, isAnnotationPresentMethods inherited from interface java.lang.reflect.GenericDeclaration
getTypeParametersMethods inherited from interface java.lang.reflect.Member
accessFlags
-
Method Details
-
from
Deprecated.ReturnsInvokableofmethod. -
from
Deprecated.ReturnsInvokableofconstructor. -
isOverridable
public abstract boolean isOverridable()Deprecated.Returnstrueif this is an overridable method. Constructors, private, static or final methods, or methods declared by final classes are not overridable. -
isVarArgs
public abstract boolean isVarArgs()Deprecated.Returnstrueif this was declared to take a variable number of arguments. -
invoke
public final R invoke(@Nullable T receiver, Object... args) throws InvocationTargetException, IllegalAccessException Deprecated.Invokes withreceiveras 'this' andargspassed to the underlying method and returns the return value; or calls the underlying constructor withargsand returns the constructed instance.- Throws:
IllegalAccessException- if thisConstructorobject enforces Java language access control and the underlying method or constructor is inaccessible.IllegalArgumentException- if the number of actual and formal parameters differ; if an unwrapping conversion for primitive arguments fails; or if, after possible unwrapping, a parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion.InvocationTargetException- if the underlying method or constructor throws an exception.
-
getReturnType
Deprecated.Returns the return type of thisInvokable. -
getParameters
Deprecated.Returns all declared parameters of thisInvokable. Note that if this is a constructor of a non-static inner class, unlikeConstructor.getParameterTypes(), the hiddenthisparameter of the enclosing class is excluded from the returned parameters. -
getExceptionTypes
Deprecated.Returns all declared exception types of thisInvokable. -
returning
Deprecated.Explicitly specifies the return type of thisInvokable. For example:Method factoryMethod = Person.class.getMethod("create"); Invokable<?, Person> factory = Invokable.of(getNameMethod).returning(Person.class); -
returning
Deprecated.Explicitly specifies the return type of thisInvokable. -
getDeclaringClass
Deprecated.- Specified by:
getDeclaringClassin interfaceMember
-
getOwnerType
Deprecated.Returns the type ofT. -
isAnnotationPresent
Deprecated.- Specified by:
isAnnotationPresentin interfaceAnnotatedElement- Overrides:
isAnnotationPresentin classAccessibleObject
-
getAnnotation
Deprecated.- Specified by:
getAnnotationin interfaceAnnotatedElement- Overrides:
getAnnotationin classAccessibleObject
-
getAnnotations
Deprecated.- Specified by:
getAnnotationsin interfaceAnnotatedElement- Overrides:
getAnnotationsin classAccessibleObject
-
getDeclaredAnnotations
Deprecated.- Specified by:
getDeclaredAnnotationsin interfaceAnnotatedElement- Overrides:
getDeclaredAnnotationsin classAccessibleObject
-
setAccessible
Deprecated.- Overrides:
setAccessiblein classAccessibleObject- Throws:
SecurityException
-
isAccessible
public final boolean isAccessible()Deprecated.- Overrides:
isAccessiblein classAccessibleObject
-
getName
Deprecated. -
getModifiers
public final int getModifiers()Deprecated.- Specified by:
getModifiersin interfaceMember
-
isSynthetic
public final boolean isSynthetic()Deprecated.- Specified by:
isSyntheticin interfaceMember
-
isPublic
public final boolean isPublic()Deprecated.Returns true if the element is public. -
isProtected
public final boolean isProtected()Deprecated.Returns true if the element is protected. -
isPackagePrivate
public final boolean isPackagePrivate()Deprecated.Returns true if the element is package-private. -
isPrivate
public final boolean isPrivate()Deprecated.Returns true if the element is private. -
isStatic
public final boolean isStatic()Deprecated.Returns true if the element is static. -
isFinal
public final boolean isFinal()Deprecated.Returnstrueif this method is final, perModifier.isFinal(getModifiers()).Note that a method may still be effectively "final", or non-overridable when it has no
finalkeyword. For example, it could be private, or it could be declared by a final class. To tell whether a method is overridable, useisOverridable(). -
isAbstract
public final boolean isAbstract()Deprecated.Returns true if the method is abstract. -
isNative
public final boolean isNative()Deprecated.Returns true if the element is native. -
isSynchronized
public final boolean isSynchronized()Deprecated.Returns true if the method is synchronized. -
equals
Deprecated. -
hashCode
public int hashCode()Deprecated. -
toString
Deprecated.
-