Top Description Methods
jakarta.enterprise.invoke

public Interface Invoker<T, R>

Type Parameters
<T>
type of the target bean
<R>
return type of the target method

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 that invoker is an invoker for the hello() method of the MyService bean and myService is a contextual reference for the bean. Then, to invoke the hello() method indirectly, a framework would call
invoker.invoke(myService, new Object[] { "world" })
The return value would be "Hello world!".
Since
4.1
See Also
invoke(Object, Object[])

Method Summary

Modifier and TypeMethod and Description
public R

Returns:

return value of the target method, or null if the target method is declared void
invoke
(T
the instance of the target bean on which the target method is to be invoked; may only be null if the target method is static
instance
,
Object[]
arguments to be passed to the target method; may only be null if the target method declares no parameter
arguments
)

Invokes the target method on the given instance of the target bean, passing given arguments.

Method Detail

invokeback to summary
public R invoke(T instance, Object[] arguments) throws Exception

Invokes the target method on the given instance of the target bean, passing given arguments. If the target method returns normally, this method returns its return value, unless the target method is declared void, in which case this method returns null. If the target method throws an exception, it is rethrown directly.

Parameters
instance:T

the instance of the target bean on which the target method is to be invoked; may only be null if the target method is static

arguments:Object[]

arguments to be passed to the target method; may only be null if the target method declares no parameter

Returns:R

return value of the target method, or null if the target method is declared void

Exceptions
Exception:
when the target method throws an exception
RuntimeException:
when instance or arguments are incorrect