java - Is it possible to retrieve lambda expression at runtime -


Last night, playing with Java8 Lombda, and I was wondering if it is possible to achieve Lambda expression at runtime. In short and as far as I understand, long expression is converted into a (static) method, and then called using Inxicinics.

Let's take an example like this:

  people.filter (person -> person.get ()> = minAge);   

Where filters as a parameter Predicate & lt; T & gt; Within a filter method, I will explain how the expression of Lambda ( person -> person.getage () & gt; = minAge < / Code) in the same form (or similar)>) in this case?

I tried to read the Generated Bytecode of Logic Class using ASM5 BETA but I could not go ahead using Class Visitor and Method Visitor to reach the method linked to Lambda Expression. Public & lt; T & gt; & Lt; T & gt; Filter (Filter T & gt; Expression} {try {class & lt;? Filter & gt; Enhances Expression class = expression .getClass (); Byte [] Content = getClassContent (Expression class); ClassReader class reader = new classifier (content); ClassReader.accept (new PredicateClassVisitor (), 0); } Hold (Throbable E) {e.printStackTrace (); } Return tap; } Private byte throws IOException [] GetClassContent (class increment filters; expression claza) {InputStream stream = Thread.currentThread () GetContextClassLoader () .getResourceAsStream (getClassName (expressionClazz.getName ())); Return IOUtils.toByteArray (stream); } Private string getClassName (String Expression Clause) {Return Expression Clauses. String (0, expression clause. Indexoff ('$')). Replace ('.', '/') + ".class"; } Fixed class extension PredicateClassVisitor class visitor {public PredicateClassVisitor () {super (Opcodes.ASM4); } @ Override Public Lawm visitMethod (int i, string s, string s2, string s3, string [] string) {New PredicateMethodVisitor back (); }} Stable class extends PredicateMethodVisitor Method Visitor {public PredicateMethodVisitor () {super (Opcodes.ASM4); } @ Override public void visitInvokeDynamicInsn (string name, string des, bsm, object ... BSMARG) {object object: BSMARGS} {System.out.println ("+ object.toString ());}}}

I'm not sure that this is the right way, and I was thinking that if there is suitable tooling for such a purpose in ASM or JDK8.>

Thank you for any advice ;-) Best regards, Xavier

You already know that The Ambada quote is generally compiled in a synthetic method, so you already know what code to decompile to get the source code of Lambda, or, OK, something or something similar to the original code Based on the special code, it looks completely different.

There is no reason why decompressing a lambda expression can be easy to reduce any other Java expression. Recovering the expressions can be easy, especially when the code contains information about debugging, when complex expression is different at the time of decompiling, especially when implementing optimization for the compiler code.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -