< prev index next >

src/java.base/share/classes/java/lang/invoke/LambdaMetafactory.java

Print this page




 132  * <ul>
 133  *     <li>Rd is an interface</li>
 134  *     <li>{@code implMethod} is a <em>direct method handle</em></li>
 135  *     <li>{@code samMethodType} and {@code instantiatedMethodType} have the same
 136  *     arity N, and for i=1..N, Ti and Ui are the same type, or Ti and Ui are
 137  *     both reference types and Ti is a subtype of Ui</li>
 138  *     <li>Either Rt and Ru are the same type, or both are reference types and
 139  *     Rt is a subtype of Ru</li>
 140  *     <li>K + N = M</li>
 141  *     <li>For i=1..K, Di = Ai</li>
 142  *     <li>For i=1..N, Ti is adaptable to Aj, where j=i+k</li>
 143  *     <li>The return type Rt is void, or the return type Ra is not void and is
 144  *     adaptable to Rt</li>
 145  * </ul>
 146  *
 147  * <p>Further, at capture time, if {@code implMethod} corresponds to an instance
 148  * method, and there are any capture arguments ({@code K > 0}), then the first
 149  * capture argument (corresponding to the receiver) must be non-null.
 150  *
 151  * <p>A type Q is considered adaptable to S as follows:
 152  * <table summary="adaptable types">


 153  *     <tr><th>Q</th><th>S</th><th>Link-time checks</th><th>Invocation-time checks</th></tr>


 154  *     <tr>
 155  *         <td>Primitive</td><td>Primitive</td>
 156  *         <td>Q can be converted to S via a primitive widening conversion</td>
 157  *         <td>None</td>
 158  *     </tr>
 159  *     <tr>
 160  *         <td>Primitive</td><td>Reference</td>
 161  *         <td>S is a supertype of the Wrapper(Q)</td>
 162  *         <td>Cast from Wrapper(Q) to S</td>
 163  *     </tr>
 164  *     <tr>
 165  *         <td>Reference</td><td>Primitive</td>
 166  *         <td>for parameter types: Q is a primitive wrapper and Primitive(Q)
 167  *         can be widened to S
 168  *         <br>for return types: If Q is a primitive wrapper, check that
 169  *         Primitive(Q) can be widened to S</td>
 170  *         <td>If Q is not a primitive wrapper, cast Q to the base Wrapper(S);
 171  *         for example Number for numeric types</td>
 172  *     </tr>
 173  *     <tr>
 174  *         <td>Reference</td><td>Reference</td>
 175  *         <td>for parameter types: S is a supertype of Q
 176  *         <br>for return types: none</td>
 177  *         <td>Cast from Q to S</td>
 178  *     </tr>

 179  * </table>
 180  *
 181  * @apiNote These linkage methods are designed to support the evaluation
 182  * of <em>lambda expressions</em> and <em>method references</em> in the Java
 183  * Language.  For every lambda expressions or method reference in the source code,
 184  * there is a target type which is a functional interface.  Evaluating a lambda
 185  * expression produces an object of its target type. The recommended mechanism
 186  * for evaluating lambda expressions is to desugar the lambda body to a method,
 187  * invoke an invokedynamic call site whose static argument list describes the
 188  * sole method of the functional interface and the desugared implementation
 189  * method, and returns an object (the lambda object) that implements the target
 190  * type. (For method references, the implementation method is simply the
 191  * referenced method; no desugaring is needed.)
 192  *
 193  * <p>The argument list of the implementation method and the argument list of
 194  * the interface method(s) may differ in several ways.  The implementation
 195  * methods may have additional arguments to accommodate arguments captured by
 196  * the lambda expression; there may also be differences resulting from permitted
 197  * adaptations of arguments, such as casting, boxing, unboxing, and primitive
 198  * widening. (Varargs adaptations are not handled by the metafactories; these are




 132  * <ul>
 133  *     <li>Rd is an interface</li>
 134  *     <li>{@code implMethod} is a <em>direct method handle</em></li>
 135  *     <li>{@code samMethodType} and {@code instantiatedMethodType} have the same
 136  *     arity N, and for i=1..N, Ti and Ui are the same type, or Ti and Ui are
 137  *     both reference types and Ti is a subtype of Ui</li>
 138  *     <li>Either Rt and Ru are the same type, or both are reference types and
 139  *     Rt is a subtype of Ru</li>
 140  *     <li>K + N = M</li>
 141  *     <li>For i=1..K, Di = Ai</li>
 142  *     <li>For i=1..N, Ti is adaptable to Aj, where j=i+k</li>
 143  *     <li>The return type Rt is void, or the return type Ra is not void and is
 144  *     adaptable to Rt</li>
 145  * </ul>
 146  *
 147  * <p>Further, at capture time, if {@code implMethod} corresponds to an instance
 148  * method, and there are any capture arguments ({@code K > 0}), then the first
 149  * capture argument (corresponding to the receiver) must be non-null.
 150  *
 151  * <p>A type Q is considered adaptable to S as follows:
 152  * <table class="borderless">
 153  *   <caption style="display:none">adaptable types</caption>
 154  *   <thead>
 155  *     <tr><th>Q</th><th>S</th><th>Link-time checks</th><th>Invocation-time checks</th></tr>
 156  *   </thead>
 157  *   <tbody>
 158  *     <tr>
 159  *         <td>Primitive</td><td>Primitive</td>
 160  *         <td>Q can be converted to S via a primitive widening conversion</td>
 161  *         <td>None</td>
 162  *     </tr>
 163  *     <tr>
 164  *         <td>Primitive</td><td>Reference</td>
 165  *         <td>S is a supertype of the Wrapper(Q)</td>
 166  *         <td>Cast from Wrapper(Q) to S</td>
 167  *     </tr>
 168  *     <tr>
 169  *         <td>Reference</td><td>Primitive</td>
 170  *         <td>for parameter types: Q is a primitive wrapper and Primitive(Q)
 171  *         can be widened to S
 172  *         <br>for return types: If Q is a primitive wrapper, check that
 173  *         Primitive(Q) can be widened to S</td>
 174  *         <td>If Q is not a primitive wrapper, cast Q to the base Wrapper(S);
 175  *         for example Number for numeric types</td>
 176  *     </tr>
 177  *     <tr>
 178  *         <td>Reference</td><td>Reference</td>
 179  *         <td>for parameter types: S is a supertype of Q
 180  *         <br>for return types: none</td>
 181  *         <td>Cast from Q to S</td>
 182  *     </tr>
 183  *   </tbody>
 184  * </table>
 185  *
 186  * @apiNote These linkage methods are designed to support the evaluation
 187  * of <em>lambda expressions</em> and <em>method references</em> in the Java
 188  * Language.  For every lambda expressions or method reference in the source code,
 189  * there is a target type which is a functional interface.  Evaluating a lambda
 190  * expression produces an object of its target type. The recommended mechanism
 191  * for evaluating lambda expressions is to desugar the lambda body to a method,
 192  * invoke an invokedynamic call site whose static argument list describes the
 193  * sole method of the functional interface and the desugared implementation
 194  * method, and returns an object (the lambda object) that implements the target
 195  * type. (For method references, the implementation method is simply the
 196  * referenced method; no desugaring is needed.)
 197  *
 198  * <p>The argument list of the implementation method and the argument list of
 199  * the interface method(s) may differ in several ways.  The implementation
 200  * methods may have additional arguments to accommodate arguments captured by
 201  * the lambda expression; there may also be differences resulting from permitted
 202  * adaptations of arguments, such as casting, boxing, unboxing, and primitive
 203  * widening. (Varargs adaptations are not handled by the metafactories; these are


< prev index next >