Class 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, Member

    public abstract class Invokable<T,​R>
    extends Object
    implements AnnotatedElement, Member
    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());
     

    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.

    Since:
    14.0 (no longer implements AccessibleObject or GenericDeclaration since 31.0)
    Author:
    Ben Yu