--- 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);
}