forked from JavaTX/JavaCompilerCore
LambdaTest Funktioniert.
This commit is contained in:
parent
448d3e04f8
commit
14be882b7b
@ -581,7 +581,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
// ")"+lam.getReturn.getBounds
|
// ")"+lam.getReturn.getBounds
|
||||||
Signature sig = new Signature(lambdaExpression, numberOfParams);
|
Signature sig = new Signature(lambdaExpression, numberOfParams);
|
||||||
String name = "Fun" + 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);
|
Type.getInternalName(Object.class), null);
|
||||||
MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc,
|
MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc,
|
||||||
methSig.toString(), null);
|
methSig.toString(), null);
|
||||||
|
@ -31,12 +31,16 @@ public class LambdaTest {
|
|||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("Lambda");
|
classToTest = loader.loadClass("Lambda");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
Method m = classToTest.getDeclaredMethod("m");
|
Method m = classToTest.getDeclaredMethod("m");
|
||||||
Class<?> lambda = m.invoke(instanceOfClass).getClass();
|
Class<?> lambda = m.invoke(instanceOfClass).getClass();
|
||||||
Method apply = lambda.getMethod("apply", Object.class);
|
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.
|
apply.setAccessible(true);
|
||||||
assertEquals(77, result);
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user