jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java
changeset 26478 285691ed55e4
parent 26477 e095a2b8a1f8
child 26482 cea1ab1c3ac7
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Wed Sep 10 19:19:51 2014 +0400
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Wed Sep 10 19:19:51 2014 +0400
@@ -2024,8 +2024,11 @@
      */
     public static
     MethodHandle explicitCastArguments(MethodHandle target, MethodType newType) {
-        if (!target.type().isCastableTo(newType)) {
-            throw new WrongMethodTypeException("cannot explicitly cast "+target+" to "+newType);
+        MethodType oldType = target.type();
+        // use the asTypeCache when possible:
+        if (oldType == newType)  return target;
+        if (oldType.explicitCastEquivalentToAsType(newType)) {
+            return target.asType(newType);
         }
         return MethodHandleImpl.makePairwiseConvert(target, newType, false);
     }