LambdaTest Funktioniert.

This commit is contained in:
Fayez Abu Alia 2018-07-18 22:49:21 +02:00
parent 448d3e04f8
commit 14be882b7b
2 changed files with 8 additions and 4 deletions

View File

@ -581,7 +581,7 @@ public class BytecodeGenMethod implements StatementVisitor {
// ")"+lam.getReturn.getBounds
Signature sig = new Signature(lambdaExpression, numberOfParams);
String name = "Fun" + numberOfParams + "$$";
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
Type.getInternalName(Object.class), null);
MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc,
methSig.toString(), null);

View File

@ -35,8 +35,12 @@ public class LambdaTest {
Method m = classToTest.getDeclaredMethod("m");
Class<?> lambda = m.invoke(instanceOfClass).getClass();
Method apply = lambda.getMethod("apply", Object.class);
Integer result = (Integer) apply.invoke(lambda, new Integer(77)); //laeuft nicht, vermutlich weil Lambda-Ausdrucks Methode "apply" private ist.
assertEquals(77, result);
apply.setAccessible(true);
Integer i = 77;
// result = 77*77 = 5929
Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i); //laeuft nicht, vermutlich weil Lambda-Ausdrucks Methode "apply" private ist.
assertEquals(5929, result);
}