Method class abstract

Provides reflective access to class method metadata and invocation capabilities.

This interface enables runtime inspection and invocation of class methods, including access to:

  • Method signatures and return types
  • Parameter metadata
  • Modifiers (static, abstract, etc.)
  • Type parameters
  • Override information

{@template method_interface_features}

Key Features

  • Type-safe method invocation
  • Full signature inspection
  • Parameter metadata access
  • Override hierarchy navigation
  • Generic type support

Implementation Notes

Concrete implementations typically wrap platform-specific reflection objects while providing this uniform interface.

Example Usage

// Get method metadata
final toStringMethod = objectClass.getMethod('toString');

// Inspect method properties
print('Return type: ${toStringMethod.getReturnType<String>().getName()}');

// Invoke the method
final result = toStringMethod.invoke(myObject);
print('Result: $result');

// Check override status
if (toStringMethod.isOverride()) {
  print('This overrides a superclass method');
}

{@endtemplate}

Inheritance
Implemented types

Constructors

Method()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

canAcceptArguments(Map<String, dynamic> arguments) bool
Checks if named arguments can be accepted.
inherited
canAcceptNamedArguments(Map<String, dynamic> arguments) bool
Checks if named arguments can be accepted.
inherited
canAcceptPositionalArguments(List args) bool
Checks if positional arguments can be accepted.
inherited
checkAccess(String operation, DomainPermission permission) → void
Verifies access permissions before performing sensitive operations.
inherited
componentType<C>() Class<C>?
Retrieves the element or value type (C) of a collection-like or container-like generic structure.
inherited
getAllDirectAnnotations() List<Annotation>
Gets all annotations applied to this element.
inherited
getDeclaration() Declaration
Gets the type declaration metadata for this class.
inherited
getDeclaringClass<D>() Class<D>
Gets the class that declares this method.
inherited
getDirectAnnotation<A>() → A?
Gets a single annotation by type, if present.
inherited
getDirectAnnotations<A>() List<A>
Gets all annotations of a specific type.
inherited
getModifiers() List<String>
Returns the list of modifiers associated with this source element.
inherited
getName() String
Gets the declared name of the source.
inherited
getOverriddenMethod() Method?
Gets the method that this method overrides.
getParameter(String name) Parameter?
Gets a parameter by name.
inherited
getParameterAt(int index) Parameter?
Gets a parameter by index.
inherited
getParameterCount() int
Gets the total number of parameters.
inherited
getParameters() List<Parameter>
Gets all parameters of this executable element.
inherited
getParameterTypes() List<Class>
Gets the types of all parameters.
inherited
getProtectionDomain() ProtectionDomain
Gets the protection domain governing access to this element.
inherited
getReturnClass() Class<Object>
Gets the return type of the method.
inherited
getReturnType() Type
Gets the return type of the method.
inherited
getSignature() String
Gets the executable signature as a string.
inherited
getTypeParameters() List<Class>
Returns all declared type parameters of this class in the order they appear in the class declaration.
inherited
hasDirectAnnotation<A>() bool
Checks if this element has a specific annotation.
inherited
hasGenerics() bool
Checks if this class has generic type parameters.
inherited
invoke(Object? instance, [Map<String, dynamic>? arguments, List args = const []]) → dynamic
Invokes the method on an instance with named arguments.
isAbstract() bool
Checks if this method is abstract.
isAsync() bool
Determines whether this method is asynchronous — i.e., declared using the async keyword or returning a Future-like type.
isConst() bool
Checks if this executable is declared as const.
inherited
isFactory() bool
Checks if this method is a factory constructor.
isFutureVoid() bool
Determines whether this method declares a Future<void> return type.
isGetter() bool
Checks if this method is a getter.
isKeyValuePaired() bool
Checks if this class represents a key-value pair type.
inherited
isOverride() bool
Checks if this method overrides a superclass method.
isPublic() bool
Checks if this element is public.
inherited
isSetter() bool
Checks if this method is a setter.
isStatic() bool
Checks if this method is static.
isVoid() bool
Determines whether this method declares a void return type.
keyType<K>() Class<K>?
Retrieves the key type (K) of a map-like or pair-like generic structure.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

declared(MethodDeclaration declaration, ProtectionDomain domain) Method
Creates a Method instance from reflection metadata.