How do I create Java 8 Consumer code via Sun JCodeModel

211 Views Asked by At

How do I create Java 8 code that looks like this, without using the version with "com.sun.codemodel.JExpr.direct(String)":

Goal (the whole line would look like this, but the part I'm interested in is only the second parameter (java.util.function.Consumer) of the consumer method):

consume("someValue", myInstance::methodToBeUsed);

Currently in use to generate that part of the code:

JExpr.direct("instance" + "::" + "methodToBeUsed");

Just for clarity, the consume method:

import java.util.function.Consumer;

public class Foo {
    public static void consume(String value, Consumer<String> c) {
        c.accept(value);
    }
}
0

There are 0 best solutions below