Package jakarta.enterprise.invoke
Interface Invoker<T,R>
-
- Type Parameters:
T
- type of the target beanR
- return type of the target method
public interface Invoker<T,R>
An invoker allows indirect invocation of its target method on an instance of its target bean.CDI-based frameworks are expected to use invokers when they need to invoke application methods. Applications are not supposed to use invokers, as they can invoke their own methods directly.
For example, assume the following managed bean exists:
@Dependent public class MyService { public String hello(String name) { return "Hello " + name + "!"; } }
Further, assume thatinvoker
is an invoker for thehello()
method of theMyService
bean andmyService
is a contextual reference for the bean. Then, to invoke thehello()
method indirectly, a framework would callinvoker.invoke(myService, new Object[] { "world" })
The return value would be"Hello world!"
.- Since:
- 4.1
- See Also:
invoke(Object, Object[])
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description R
invoke(T instance, java.lang.Object[] arguments)
Invokes the target method on the giveninstance
of the target bean, passing givenarguments
.
-
-
-
Method Detail
-
invoke
R invoke(T instance, java.lang.Object[] arguments) throws java.lang.Exception
Invokes the target method on the giveninstance
of the target bean, passing givenarguments
. If the target method returns normally, this method returns its return value, unless the target method is declaredvoid
, in which case this method returnsnull
. If the target method throws an exception, it is rethrown directly.- Parameters:
instance
- the instance of the target bean on which the target method is to be invoked; may only benull
if the target method isstatic
arguments
- arguments to be passed to the target method; may only benull
if the target method declares no parameter- Returns:
- return value of the target method, or
null
if the target method is declaredvoid
- Throws:
java.lang.RuntimeException
- wheninstance
orarguments
are incorrectjava.lang.Exception
- when the target method throws an exception
-
-