changeset 6000:3012c72bf3da

Clarify type conversion
author Robert Field <Robert.Field@oracle.com>
date Thu, 13 Sep 2012 08:39:13 -0700
parents f0cf4b53d08d
children de7001697e00
files src/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java src/share/classes/java/lang/invoke/LambdaMetafactory.java
diffstat 2 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java	Thu Sep 13 01:13:16 2012 -0700
+++ b/src/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java	Thu Sep 13 08:39:13 2012 -0700
@@ -256,7 +256,8 @@
      * Check type adaptability
      * @param fromType
      * @param toType
-     * @return True if 'fromType' can be converted to 'toType'
+     * @param strict If true, do strict checks, else allow that fromType may be parameterized
+     * @return True if 'fromType' can be passed to an argument of 'toType'
      */
     private boolean isAdaptableTo(Class<?> fromType, Class<?> toType, boolean strict) {
         if (fromType.equals(toType)) {
@@ -293,7 +294,7 @@
     }
 
     /**
-     * Check type adaptability for return types (special handling of void type)
+     * Check type adaptability for return types -- special handling of void type) and parameterized fromType
      * @param fromType
      * @param toType
      * @return True if 'fromType' can be converted to 'toType'
--- a/src/share/classes/java/lang/invoke/LambdaMetafactory.java	Thu Sep 13 01:13:16 2012 -0700
+++ b/src/share/classes/java/lang/invoke/LambdaMetafactory.java	Thu Sep 13 08:39:13 2012 -0700
@@ -103,6 +103,12 @@
  *     <li>The return type Rt is void, or the return type Ra is not void and is adaptable to Rt</li>
  * </ul>
  *
+ * <p>Note that the potentially parameterized implementation return type provides the value for the SAM. Whereas
+ * the completely known instantiated return type is adapted to the implementation arguments. Because the
+ * instantiated type of the implementation method is not available, the adaptability of return types cannot be
+ * checked as precisely at link-time as arguments. Thus a loose version of link-time checking is done on return
+ * type, while a strict version is applied to arguments.
+ *
  * <p>A type Q is considered adaptable to S as follows:
  * <table>
  *     <tr><th>Q</th><th>S</th><th>Link-time checks</th><th>Capture-time checks</th></tr>
@@ -120,7 +126,7 @@
  *         <td>Reference</td><td>Primitive</td>
  *         <td>strict: Q is a primitive wrapper and Primitive(Q) can be widened to S
  *         <br>loose: If Q is a primitive wrapper, check that Primitive(Q) can be widened to S</td>
- *         <td>If Q is not a primitive wrapper, cast Q to Wrapper(S)</td>
+ *         <td>If Q is not a primitive wrapper, cast Q to the base Wrapper(S); for example Number for numeric types</td>
  *     </tr>
  *     <tr>
  *         <td>Reference</td><td>Reference</td>