Hi Daniel I very much recommend going with option 2: It could and should work for any functional interface, not just the ones implemented in Groovy. Ideally, there would be no difference between a "Java lambda" and a "Groovy lambda"
-Jesper > On 30 Jan 2018, at 01.14, Daniel Sun <realblue...@hotmail.com> wrote: > > Hi all, > > I'm trying to implement the callable native lambda(e.g. > `Function<Integer, Integer> f = e -> e + 1; assert 3 == f(2);`), and there > are 2 ideas come to my mind: > > 1) Generate a proxy implementing the FunctionInterface(e.g. `Function`, > `Consumer`, etc.) and a `Callable` interface(maybe we should create a new > one), the proxy will delegate invocations of `call(Object... args)` method > of `Callable` to the method of the FunctionInterface. As you know, `f(2)` is > actually `f.call(2)`, so we need the method `call`. > 2) Transform `f(2)` to `f.apply(2)`, we can get the target method name by > the type of FunctionInterface. To make it clear, let's have a look at two > example: `Function`'s method is `apply`, `Consumer`'s method is `accept`. > > I prefer the first way, but I want to get advice from you :-) > > In addition, have you any idea about the issue[1]? If you do not know > off the top of your head, I'll have to investigate when I have some spare > time. Any help is appreciated! > > Cheers, > Daniel.Sun > > [1] > https://github.com/apache/groovy/blob/native-lambda/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java#L136 > > > > -- > Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html