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

annotationMatches<A>(Annotation annotation) bool
inherited
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
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
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
hasDirectAnnotation<A>() bool
Checks if this element has a specific annotation.
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.
isConst() bool
Checks if this executable is declared as const.
inherited
isFactory() bool
Checks if this method is a factory constructor.
isGetter() bool
Checks if this method is a getter.
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.
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.