Method class abstract final

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.declared(MethodDeclaration declaration, ProtectionDomain domain, [ClassDeclaration? parent])
Creates a Method instance from reflection metadata.
factory

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() Iterable<Annotation>
Gets all annotations applied to this element.
inherited
getAuthor() Author?
Retrieves the Author annotation applied to this element, if present.
inherited
getDeclaration() MethodDeclaration
Gets the type declaration metadata for this class.
override
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>() Iterable<A>
Gets all annotations of a specific type.
inherited
getIsEntryPoint() bool
Determines whether this method represents a Dart entrypoint, typically used as the starting execution method for an application.
getIsTopLevel() bool
Determines whether this method is a top-level function rather than a class, mixin, or extension member.
getLinkDeclaration() LinkDeclaration
Gets the underlying link-time declaration for this method.
getModifiers() List<String>
Returns the list of modifiers associated with this source element.
inherited
getName() String
Gets the declared name of the source.
inherited
getNamedParameters() Iterable<Parameter>
Gets all named parameters declared by this executable.
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() Iterable<Parameter>
Gets all parameters of this executable element.
inherited
getParameterTypes() Iterable<Class>
Gets the types of all parameters.
inherited
getPositionalParameters() Iterable<Parameter>
Gets all positional parameters declared by this executable.
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() Iterable<Class>
Returns all declared type parameters of this class in the order they appear in the class declaration.
inherited
getVersion() Version
Retrieves the version metadata associated with this declaration, if any.
inherited
hasDirectAnnotation<A>() bool
Checks if this element has a specific annotation.
inherited
hasGenerics() bool
Checks if this class has generic type parameters.
inherited
hasNullableReturn() bool
Indicates whether the method’s return type is nullable.
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
isDynamic() bool
Determines whether the method declares a return type of dynamic.
isExternal() bool
Checks whether this method is declared using the external keyword.
isFactory() bool
Checks if this method is a factory constructor.
isFunction() bool
Checks whether the method's type is a function type.
isFutureDynamic() bool
Determines whether this method declares a Future<dynamic> return type.
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