Facilitates the creation of simple "function objects" that implement one or more interfaces by delegation to a provided
MethodHandle
, after appropriate type adaptation and partial evaluation of arguments. Typically used as a
bootstrap method for
invokedynamic
call sites, to support the
lambda expression and
method reference expression features of the Java Programming Language.
This is the general, more flexible metafactory; a streamlined version is provided by metafactory(java.lang.invoke.MethodHandles.Lookup, String, MethodType, MethodType, MethodHandle, MethodType)
. A general description of the behavior of this method is provided above
.
The argument list for this method includes three fixed parameters, corresponding to the parameters automatically stacked by the VM for the bootstrap method in an invokedynamic
invocation, and an Object[]
parameter that contains additional parameters. The declared argument list for this method is:
CallSite altMetafactory(MethodHandles.Lookup caller,
String invokedName,
MethodType invokedType,
Object... args)
but it behaves as if the argument list is as follows:
CallSite altMetafactory(MethodHandles.Lookup caller,
String invokedName,
MethodType invokedType,
MethodType samMethodType,
MethodHandle implMethod,
MethodType instantiatedMethodType,
int flags,
int markerInterfaceCount, // IF flags has MARKERS set
Class... markerInterfaces, // IF flags has MARKERS set
int bridgeCount, // IF flags has BRIDGES set
MethodType... bridges // IF flags has BRIDGES set
)
Arguments that appear in the argument list for metafactory(MethodHandles.Lookup, String, MethodType, MethodType, MethodHandle, MethodType)
have the same specification as in that method. The additional arguments are interpreted as follows:
-
flags
indicates additional options; this is a bitwise OR of desired flags. Defined flags are FLAG_BRIDGES
, FLAG_MARKERS
, and FLAG_SERIALIZABLE
.
-
markerInterfaceCount
is the number of additional interfaces the function object should implement, and is present if and only if the FLAG_MARKERS
flag is set.
-
markerInterfaces
is a variable-length list of additional interfaces to implement, whose length equals markerInterfaceCount
, and is present if and only if the FLAG_MARKERS
flag is set.
-
bridgeCount
is the number of additional method signatures the function object should implement, and is present if and only if the FLAG_BRIDGES
flag is set.
-
bridges
is a variable-length list of additional methods signatures to implement, whose length equals bridgeCount
, and is present if and only if the FLAG_BRIDGES
flag is set.
Each class named by markerInterfaces
is subject to the same restrictions as Rd
, the return type of invokedType
, as described above
. Each MethodType
named by bridges
is subject to the same restrictions as samMethodType
, as described above
.
When FLAG_SERIALIZABLE is set in flags
, the function objects will implement Serializable
, and will have a writeReplace
method that returns an appropriate SerializedLambda
. The caller
class must have an appropriate $deserializeLambda$
method, as described in SerializedLambda
.
When the target of the CallSite
returned from this method is invoked, the resulting function objects are instances of a class with the following properties:
- The class implements the interface named by the return type of
invokedType
and any interfaces named by markerInterfaces
- The class declares methods with the name given by
invokedName
, and the signature given by samMethodType
and additional signatures given by bridges
- The class may override methods from
Object
, and may implement methods related to serialization.