From 1ad4cfcb2146414a4375c40c05d14b4fa33c12ee Mon Sep 17 00:00:00 2001 From: Victorious3 Date: Wed, 1 Mar 2023 10:49:03 +0100 Subject: [PATCH] Let lambda functions use Object instead of generic parameters --- src/main/java/de/dhbwstuttgart/bytecode/Codegen.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java index d9b41787..7403f2e1 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java @@ -705,11 +705,15 @@ public class Codegen { } else { var name = "lambda$" + lambdaCounter++; var parameters = new ArrayList<>(lambda.captures()); - parameters.addAll(lambda.params()); + parameters.addAll(lambda.params().stream() + .map(param -> param.type() instanceof TargetGenericType ? new MethodParameter(TargetType.Object, param.name()) : param) + .toList()); impl = new TargetMethod( 0, name, Set.of(), Set.of(), - parameters, lambda.returnType(), lambda.block() + parameters, + lambda.returnType() instanceof TargetGenericType ? TargetType.Object : lambda.returnType(), + lambda.block() ); generateMethod(impl); lambdas.put(lambda, impl); @@ -736,7 +740,9 @@ public class Codegen { var params = new ArrayList(); params.add(new TargetRefType(clazz.qualifiedName())); - params.addAll(lambda.captures().stream().map(MethodParameter::type).toList()); + params.addAll(lambda.captures().stream() + .map(MethodParameter::type) + .toList()); var descriptor = TargetMethod.getDescriptor(lambda.type(), params.toArray(TargetType[]::new)); mv.visitVarInsn(ALOAD, 0);