-
-
Notifications
You must be signed in to change notification settings - Fork 620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong lambda signature calculated #11
Comments
|
Constraint: The lambda has to be Serializable. Here is the test code that shows, that the generic types are erased: public class Test {
public static void main(String[] args) throws Throwable {
final Function<Integer, String> f = i -> String.valueOf(i + 1);
System.out.println("f.class: " + f.getClass());
System.out.println("f.class.methods: " + Strings.toString(f.getClass().getMethods()));
final SerializableFunction<Integer, String> lambda = t -> f.apply(t);
final SerializedLambda serializedLambda = Lambdas.getSerializedLambda(lambda).get();
final Class<?> refc = Class.forName(serializedLambda.getFunctionalInterfaceClass().replaceAll("/", "\\."));
final String name = serializedLambda.getFunctionalInterfaceMethodName();
final MethodType methodType = MethodType.fromMethodDescriptorString(
serializedLambda.getFunctionalInterfaceMethodSignature(), lambda.getClass().getClassLoader());
final MethodHandles.Lookup lookup = MethodHandles.lookup();
final MethodHandle methodHandle = lookup.findVirtual(refc, name, methodType);
System.out.println("SERIALIZED LAMBDA: " + serializedLambda);
System.out.println("METHOD TYPE: " + methodType);
System.out.println("METHOD HANDLE: " + methodHandle);
// final MethodHandle bound = methodHandle.bindTo(lambda);
// System.out.println("BOUND METHOD HANDLE: " + bound);
//
// final Object o = bound.invoke(1);
// System.out.println("f(1): " + o);
final MethodHandleInfo info = lookup.revealDirect(methodHandle);
System.out.println("METHOD HANDLE INFO: " + info);
}
} The main problem with respect to this bug is, that captured variables are part of the signature of the generated runtime lambda. I.e. the signature of the following lambda is final SerializableFunction<Integer, String> lambda = t -> f.apply(t); I will investigate, how to create a SerializedLambda instead to keep the correct signature of the underlying Function f. |
…lang collections Solution for problem vavr-io#11.
Given a
function
of typeFunction<T, R>
and a derived functionthe result of
Lambdas.getLambdaSignature(lambda)
should be(Function) -> R
but actually is(Function, Object) -> Object
.The text was updated successfully, but these errors were encountered: