Comments (3)
This: http://cr.openjdk.java.net/~briangoetz/lambda/lambda-translation.html
from vavr.
getImplMethodSignature()
does only work in simple cases (see javaslang.lambda.Lambdas
)
from vavr.
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 (Function, Object) -> Object
instead of (Integer) -> String
:
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.
from vavr.
Related Issues (20)
- LinkedHash(Map|Set) have weird complexity HOT 2
- Support high degree zip and unzip
- poor implementation of hashCode of LinkedHashMap HOT 10
- The Option.map() method not judge the expression return value is null or not HOT 3
- Vavr.io website down HOT 1
- moving from 0.10.4 to io.vavr:vavr:1.0.0-alpha-4 results in this error HOT 2
- Question about Seq interface (methods relates '? extends' type like groupBy ..etc)
- Is 1.0.0 still a thing? HOT 9
- A not-started future that is cancelled still runs. HOT 1
- IOr value HOT 4
- DoS Vulnerability was discovered in io.vavr:vavr:0.10.4 HOT 1
- Iterator.unfoldRight() eagerly evaluates provided function
- Add variadic <T1, T2, ...TN> peek()/tap() to FunctionN
- Vavr.io website down HOT 57
- vavr code compiled with 0.10.x does not run with the 1.0.0-alpha version
- Avoid synchronized block or methods HOT 2
- Strange behaviour, maybe an error when using peek on Android 5.1.1
- Site docs.vavr.io fora do ar. HOT 3
- Roadmap Suggestions for 2.0.0 HOT 10
- Make Java17+ version and transform some classes to records (Tuples, Either, Try and Validation) HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vavr.