BeanMethod<T extends Object> class
final
The description of one public instance method of an introspected class or bean, with a closure that calls it.
SpEL uses it to call methods on introspected objects, and frameworks
use the ones in BeanDefinition.annotatedMethods to call annotated
methods of beans (@Scheduled, request handlers). You write one by
hand only in a hand-written introspection.
// Person.hello(String name), called by name from an expression.
final hello = BeanMethod<Person>(
'hello',
returnType: String,
parameterTypes: const [String],
invoke: (b, args) => b.hello(args.first! as String),
);
hello.invoke(person, ['Ann']);
Spring (Java): java.lang.reflect.Method:
Method hello = Person.class.getMethod("hello", String.class);
hello.invoke(person, "Ann");
Constructors
-
BeanMethod(String name, {required Object? invoke(T bean, List<
Object?> arguments), Object? invokeNamed(T bean, List<Object?> positional, Map<Symbol, Object?> named)?, Type? returnType, List<Type> parameterTypes = const [], List<BeanParameter> parameters = const [], TypeInfo<Object?> ? returnTypeInfo, bool isFuture = false, bool isVoid = false, List<Object> annotations = const []}) -
Describes the method
nameofT, called throughinvoke(andinvokeNamedwhen it has named parameters).
Properties
-
annotations
→ List<
Object> -
The const annotations on the method.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isFuture → bool
-
Whether the method returns a non-nullable
Future(see returnTypeInfo).final - isVoid → bool
-
Whether the result (or the future's value) is
void.final - name → String
-
The method's name.
final
-
parameters
→ List<
BeanParameter> -
Every parameter (positional, then named) with its name, full type and
annotations. Written by the generator for the methods of
BeanDefinition.annotatedMethods(what a request handler needs to bind its arguments); empty in other descriptions.final -
parameterTypes
→ List<
Type> -
Declared types of the positional parameters.
final
- returnType → Type?
-
The declared return type;
nullforvoid.final -
returnTypeInfo
→ TypeInfo<
Object?> ? -
The full result type, for a
Future<T>the typeT(what a request handler's answer is converted from). Written by the generator for every method ofBeanDefinition.annotatedMethodsthat returns a value, with or without parameters;nullfor avoidmethod (see isVoid) and in other descriptions.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
annotation<
A> () → A? -
The first annotation of type
Aon the method, ornull. -
appliesTo(
Object bean) → bool -
Whether
beancan be passed to invoke: an instance ofT. A proxy that implements only the bean's interfaces (aop_proxies: interfaces) is not; call the method onAopUtils.getTarget(bean)then. -
invoke(
Object bean, List< Object?> arguments, [Map<Symbol, Object?> namedArguments = const {}]) → Object? -
Calls the method on
beanwith positionalarguments(already of the parameter types) andnamedArguments(by BeanParameter.symbol; an omitted optional one keeps its default value); returns its result (nullforvoid). ThrowsArgumentErrorwhen named arguments are given to a method described without them. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited