本文整理汇总了Java中java.lang.invoke.LambdaMetafactory.altMetafactory方法的典型用法代码示例。如果您正苦于以下问题:Java LambdaMetafactory.altMetafactory方法的具体用法?Java LambdaMetafactory.altMetafactory怎么用?Java LambdaMetafactory.altMetafactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.invoke.LambdaMetafactory
的用法示例。
在下文中一共展示了LambdaMetafactory.altMetafactory方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Throwable {
l = MethodHandles.lookup();
h = l.findVirtual(LambdaReceiver_A.class, "f", mt(int.class));
MethodType X = mt(int.class, LambdaReceiverBridge.class);
MethodType A = mt(int.class, LambdaReceiver_A.class);
MethodType mti = mt(IA.class);
CallSite cs = LambdaMetafactory.altMetafactory(l, "m", mti,X,h,X,
LambdaMetafactory.FLAG_BRIDGES, 1, A);
IA p = (IA)cs.dynamicInvoker().invoke();
LambdaReceiver_A lra = new LambdaReceiver_A();
try {
p.m(lra);
} catch (ClassCastException cce) {
return;
}
throw new AssertionError("CCE expected");
}
示例2: amf
import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
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);
}
示例3: testAltStdNonser
import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
public void testAltStdNonser() throws Throwable {
MethodHandle fooMH = MethodHandles.lookup().findStatic(SerializedLambdaTest.class, "foo", predicateMT);
// Alt metafactory, non-serializable target: not serializable
CallSite cs = LambdaMetafactory.altMetafactory(MethodHandles.lookup(),
"test", MethodType.methodType(Predicate.class),
predicateMT, fooMH, stringPredicateMT, 0);
assertNotSerial((Predicate<String>) cs.getTarget().invokeExact(), fooAsserter);
}
示例4: testAltStdSer
import java.lang.invoke.LambdaMetafactory; //导入方法依赖的package包/类
public void testAltStdSer() throws Throwable {
MethodHandle fooMH = MethodHandles.lookup().findStatic(SerializedLambdaTest.class, "foo", predicateMT);
// Alt metafactory, serializable target, no FLAG_SERIALIZABLE: not serializable
CallSite cs = LambdaMetafactory.altMetafactory(MethodHandles.lookup(),
"test", MethodType.methodType(SerPredicate.class),
predicateMT, fooMH, stringPredicateMT, 0);
assertNotSerial((SerPredicate<String>) cs.getTarget().invokeExact(), fooAsserter);
// Alt metafactory, serializable marker, no FLAG_SERIALIZABLE: not serializable
cs = LambdaMetafactory.altMetafactory(MethodHandles.lookup(),
"test", MethodType.methodType(Predicate.class),
predicateMT, fooMH, stringPredicateMT, LambdaMetafactory.FLAG_MARKERS, 1, Serializable.class);
assertNotSerial((Predicate<String>) cs.getTarget().invokeExact(), fooAsserter);
}