diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index 6b24d23b..e17f545b 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -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); diff --git a/test/bytecode/LambdaTest.java b/test/bytecode/LambdaTest.java index d36217fd..fe49809c 100644 --- a/test/bytecode/LambdaTest.java +++ b/test/bytecode/LambdaTest.java @@ -31,12 +31,16 @@ public class LambdaTest { loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass("Lambda"); instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - + 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); }