下面列出了怎么用java.lang.invoke.LambdaConversionException的API类实例代码及写法,或者点击链接到github查看源代码。
public static CallSite lambdaCapture(
MethodHandles.Lookup callerLookup,
String name,
MethodType type,
MethodType samMethodType,
MethodHandle implMethod,
MethodType instantiatedMethodType)
{
try {
// delegate to metafactory, we may choose to generate code ourselves in the future.
return LambdaMetafactory.metafactory(
callerLookup,
name,
type,
samMethodType,
implMethod,
instantiatedMethodType);
}
catch (LambdaConversionException e) {
throwIfUnchecked(e);
throw new RuntimeException(e);
}
}
private static void amf(List<String> errs, MethodHandle h, MethodType mts, MethodType mtf, MethodType mtb, boolean shouldWork) {
MethodType mti = mt(I.class);
try {
LambdaMetafactory.altMetafactory(l, "m", mti, mts,h,mtf,
LambdaMetafactory.FLAG_BRIDGES, 1, mtb);
} catch(LambdaConversionException e) {
if (shouldWork) errs.add("Error: Should work h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb + " got: " + e);
return;
}
if (!shouldWork) errs.add("Error: Should fail h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb);
}
private static boolean mf(MethodHandles.Lookup l) {
try {
LambdaMetafactory.metafactory(l, "close",
mt(Closeable.class),mt(void.class),h,mt(void.class));
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static boolean mf(Class<?> k) {
try {
LambdaMetafactory.metafactory(l, "m",
mt(I.class),mt(k),h,mt(void.class));
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static boolean mf(MethodType mti, MethodType mtf) {
try {
LambdaMetafactory.metafactory(l, "m", mti,mtf,h,mtf);
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static void amf(List<String> errs, MethodHandle h, MethodType mts, MethodType mtf, MethodType mtb, boolean shouldWork) {
MethodType mti = mt(I.class);
try {
LambdaMetafactory.altMetafactory(l, "m", mti, mts,h,mtf,
LambdaMetafactory.FLAG_BRIDGES, 1, mtb);
} catch(LambdaConversionException e) {
if (shouldWork) errs.add("Error: Should work h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb + " got: " + e);
return;
}
if (!shouldWork) errs.add("Error: Should fail h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb);
}
private static boolean mf(MethodHandles.Lookup l) {
try {
LambdaMetafactory.metafactory(l, "close",
mt(Closeable.class),mt(void.class),h,mt(void.class));
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static boolean mf(Class<?> k) {
try {
LambdaMetafactory.metafactory(l, "m",
mt(I.class),mt(k),h,mt(void.class));
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static boolean mf(MethodType mti, MethodType mtf) {
try {
LambdaMetafactory.metafactory(l, "m", mti,mtf,h,mtf);
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static void amf(List<String> errs, MethodHandle h, MethodType mts, MethodType mtf, MethodType mtb, boolean shouldWork) {
MethodType mti = mt(I.class);
try {
LambdaMetafactory.altMetafactory(l, "m", mti, mts,h,mtf,
LambdaMetafactory.FLAG_BRIDGES, 1, mtb);
} catch(LambdaConversionException e) {
if (shouldWork) errs.add("Error: Should work h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb + " got: " + e);
return;
}
if (!shouldWork) errs.add("Error: Should fail h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb);
}
private static boolean mf(MethodHandles.Lookup l) {
try {
LambdaMetafactory.metafactory(l, "close",
mt(Closeable.class),mt(void.class),h,mt(void.class));
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static boolean mf(Class<?> k) {
try {
LambdaMetafactory.metafactory(l, "m",
mt(I.class),mt(k),h,mt(void.class));
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static boolean mf(MethodType mti, MethodType mtf) {
try {
LambdaMetafactory.metafactory(l, "m", mti,mtf,h,mtf);
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static void amf(List<String> errs, MethodHandle h, MethodType mts, MethodType mtf, MethodType mtb, boolean shouldWork) {
MethodType mti = mt(I.class);
try {
LambdaMetafactory.altMetafactory(l, "m", mti, mts,h,mtf,
LambdaMetafactory.FLAG_BRIDGES, 1, mtb);
} catch(LambdaConversionException e) {
if (shouldWork) errs.add("Error: Should work h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb + " got: " + e);
return;
}
if (!shouldWork) errs.add("Error: Should fail h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb);
}
private static boolean mf(MethodHandles.Lookup l) {
try {
LambdaMetafactory.metafactory(l, "close",
mt(Closeable.class),mt(void.class),h,mt(void.class));
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static boolean mf(Class<?> k) {
try {
LambdaMetafactory.metafactory(l, "m",
mt(I.class),mt(k),h,mt(void.class));
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static boolean mf(MethodType mti, MethodType mtf) {
try {
LambdaMetafactory.metafactory(l, "m", mti,mtf,h,mtf);
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static void amf(List<String> errs, MethodHandle h, MethodType mts, MethodType mtf, MethodType mtb, boolean shouldWork) {
MethodType mti = mt(I.class);
try {
LambdaMetafactory.altMetafactory(l, "m", mti, mts,h,mtf,
LambdaMetafactory.FLAG_BRIDGES, 1, mtb);
} catch(LambdaConversionException e) {
if (shouldWork) errs.add("Error: Should work h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb + " got: " + e);
return;
}
if (!shouldWork) errs.add("Error: Should fail h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb);
}
private static boolean mf(MethodHandles.Lookup l) {
try {
LambdaMetafactory.metafactory(l, "close",
mt(Closeable.class),mt(void.class),h,mt(void.class));
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static boolean mf(Class<?> k) {
try {
LambdaMetafactory.metafactory(l, "m",
mt(I.class),mt(k),h,mt(void.class));
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static boolean mf(MethodType mti, MethodType mtf) {
try {
LambdaMetafactory.metafactory(l, "m", mti,mtf,h,mtf);
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static void amf(List<String> errs, MethodHandle h, MethodType mts, MethodType mtf, MethodType mtb, boolean shouldWork) {
MethodType mti = mt(I.class);
try {
LambdaMetafactory.altMetafactory(l, "m", mti, mts,h,mtf,
LambdaMetafactory.FLAG_BRIDGES, 1, mtb);
} catch(LambdaConversionException e) {
if (shouldWork) errs.add("Error: Should work h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb + " got: " + e);
return;
}
if (!shouldWork) errs.add("Error: Should fail h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb);
}
private static boolean mf(MethodHandles.Lookup l) {
try {
LambdaMetafactory.metafactory(l, "close",
mt(Closeable.class),mt(void.class),h,mt(void.class));
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static boolean mf(Class<?> k) {
try {
LambdaMetafactory.metafactory(l, "m",
mt(I.class),mt(k),h,mt(void.class));
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static boolean mf(MethodType mti, MethodType mtf) {
try {
LambdaMetafactory.metafactory(l, "m", mti,mtf,h,mtf);
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static void amf(List<String> errs, MethodHandle h, MethodType mts, MethodType mtf, MethodType mtb, boolean shouldWork) {
MethodType mti = mt(I.class);
try {
LambdaMetafactory.altMetafactory(l, "m", mti, mts,h,mtf,
LambdaMetafactory.FLAG_BRIDGES, 1, mtb);
} catch(LambdaConversionException e) {
if (shouldWork) errs.add("Error: Should work h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb + " got: " + e);
return;
}
if (!shouldWork) errs.add("Error: Should fail h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb);
}
private static boolean mf(MethodHandles.Lookup l) {
try {
LambdaMetafactory.metafactory(l, "close",
mt(Closeable.class),mt(void.class),h,mt(void.class));
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static boolean mf(Class<?> k) {
try {
LambdaMetafactory.metafactory(l, "m",
mt(I.class),mt(k),h,mt(void.class));
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static boolean mf(MethodType mti, MethodType mtf) {
try {
LambdaMetafactory.metafactory(l, "m", mti,mtf,h,mtf);
} catch(LambdaConversionException e) {
return true;
}
return false;
}
private static void amf(List<String> errs, MethodHandle h, MethodType mts, MethodType mtf, MethodType mtb, boolean shouldWork) {
MethodType mti = mt(I.class);
try {
LambdaMetafactory.altMetafactory(l, "m", mti, mts,h,mtf,
LambdaMetafactory.FLAG_BRIDGES, 1, mtb);
} catch(LambdaConversionException e) {
if (shouldWork) errs.add("Error: Should work h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb + " got: " + e);
return;
}
if (!shouldWork) errs.add("Error: Should fail h=" + h + " s=" + mts + " -- f=" + mtf + " / b=" + mtb);
}