コード例 #1
0
 static void tryMetafactory(
     boolean correct, MethodHandle mh, Class<?>[] captured, MethodType instMT, MethodType samMT) {
   try {
     LambdaMetafactory.metafactory(
         lookup, "run", methodType(I.class, captured), samMT, mh, instMT);
     if (!correct) {
       throw new AssertionError(
           "Uncaught linkage error:"
               + " impl="
               + mh
               + ", captured="
               + Arrays.toString(captured)
               + ", inst="
               + instMT
               + ", sam="
               + samMT);
     }
   } catch (LambdaConversionException e) {
     if (correct) {
       throw new AssertionError(
           "Unexpected linkage error:"
               + " e="
               + e
               + ", impl="
               + mh
               + ", captured="
               + Arrays.toString(captured)
               + ", inst="
               + instMT
               + ", sam="
               + samMT);
     }
   }
 }
コード例 #2
0
 static void tryAltMetafactory(
     boolean correct,
     MethodHandle mh,
     Class<?>[] captured,
     MethodType instMT,
     MethodType samMT,
     MethodType... bridgeMTs) {
   boolean bridge = bridgeMTs.length > 0;
   Object[] args = new Object[bridge ? 5 + bridgeMTs.length : 4];
   args[0] = samMT;
   args[1] = mh;
   args[2] = instMT;
   args[3] = bridge ? LambdaMetafactory.FLAG_BRIDGES : 0;
   if (bridge) {
     args[4] = bridgeMTs.length;
     for (int i = 0; i < bridgeMTs.length; i++) args[5 + i] = bridgeMTs[i];
   }
   try {
     LambdaMetafactory.altMetafactory(lookup, "run", methodType(I.class, captured), args);
     if (!correct) {
       throw new AssertionError(
           "Uncaught linkage error:"
               + " impl="
               + mh
               + ", captured="
               + Arrays.toString(captured)
               + ", inst="
               + instMT
               + ", sam="
               + samMT
               + ", bridges="
               + Arrays.toString(bridgeMTs));
     }
   } catch (LambdaConversionException e) {
     if (correct) {
       throw new AssertionError(
           "Unexpected linkage error:"
               + " e="
               + e
               + ", impl="
               + mh
               + ", captured="
               + Arrays.toString(captured)
               + ", inst="
               + instMT
               + ", sam="
               + samMT
               + ", bridges="
               + Arrays.toString(bridgeMTs));
     }
   }
 }