Skip to content

Commit

Permalink
clarify requirements on the target instance; this commit should be sq…
Browse files Browse the repository at this point in the history
…uashed before merging
  • Loading branch information
Ladicek committed Jan 12, 2024
1 parent b6de641 commit af861ea
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion spec/src/main/asciidoc/core/invokers.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public interface Invoker<T, R> {
----

Calling `invoke()` invokes the target method on given `instance` of the target bean, passing given `arguments`, and propagates back the return value or thrown exception.
The `instance` may be a non-contextual object.

Invoker implementations must be thread-safe.
A single invoker instance may be used to perform multiple, possibly concurrent, invocations of the target method, possibly on different instances of the target bean, possibly with different arguments.
Expand All @@ -57,8 +58,16 @@ Whenever a direct invocation of a method on an object is a business method invoc

If the target method is `static`, the `instance` is ignored; by convention, it should be `null`.
If the target method is not `static` and `instance` is `null`, a `RuntimeException` is thrown.
If the target method is not `static` and the class of the `instance` is not a subclass of the bean class of the target bean, a `RuntimeException` is thrown.
If the target method is not `static` and the class of the `instance` makes it impossible to invoke the target method, a `RuntimeException` is thrown.

[NOTE]
====
Usually, the class of the `instance` should be the bean class of the target bean (or a subclass), in which case, it is possible to invoke all target methods.
This is true when `instance` is a contextual reference for the target bean obtained using the bean class as the required type.
It is however permissible for the `instance` to be a reference to a type that cannot be cast to the bean class (see <<typecasting_between_bean_types>>).
In this case, invoking some target methods may be impossible.
====

Correspondence between given `arguments` and declared parameters of the target method is positional: the Nth element of the `arguments` array is passed as the Nth argument to the target method.
If the target method is a variable arity method, the last element of the `arguments` array corresponds to the variable arity parameter (and therefore must be an array).
Expand Down

0 comments on commit af861ea

Please sign in to comment.