Facilitates the creation of optimized String concatenation methods, that can be used to efficiently concatenate a known number of arguments of known types, possibly after type adaptation and partial evaluation of arguments. Typically used as a
bootstrap method for
invokedynamic
call sites, to support the
string concatenation feature of the Java Programming Language.
When the target of the CallSite
returned from this method is invoked, it returns the result of String concatenation, taking all function arguments and constants passed to the linkage method as inputs for concatenation. The target signature is given by concatType
, and does not include constants. The arguments are concatenated as per requirements stated in JLS 15.18.1 "String Concatenation Operator +". Notably, the inputs are converted as per JLS 5.1.11 "String Conversion", and combined from left to right.
The concatenation recipe is a String description for the way to construct a concatenated String from the arguments and constants. The recipe is processed from left to right, and each character represents an input to concatenation. Recipe characters mean:
-
\1 (Unicode point 0001) : an ordinary argument. This input is passed through dynamic argument, and is provided during the concatenation method invocation. This input can be null.
-
\2 (Unicode point 0002): a constant. This input passed through static bootstrap argument. This constant can be any value representable in constant pool. If necessary, the factory would call
toString
to perform a one-time String conversion.
-
Any other char value: a single character constant.
Assume the linkage arguments are as follows:
-
concatType
, describing the CallSite
signature
-
recipe
, describing the String recipe
-
constants
, the vararg array of constants
Then the following linkage invariants must hold:
- The parameter count in
concatType
is less than or equal to 200
- The parameter count in
concatType
equals to number of \1 tags in recipe
- The return type in
concatType
is assignable from String
, and matches the return type of the returned MethodHandle
- The number of elements in
constants
equals to number of \2 tags in recipe