0

I saw this example

How to convert a string to a lambda expression? expression

of how to convert a string into a java function

using this code snippet:

import java.util.function.Function;
import javax.script.*;

public class ScriptFunction {
    public static void main(String[] args) throws Exception {
    ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
    @SuppressWarnings("unchecked")
    Function<Object,Object> f = (Function<Object,Object>)engine.eval(
        String.format("new java.util.function.Function(%s)", args[0]));
    for (int i = 1; i < args.length; i++) {
        System.out.println(f.apply(args[i]));
    }
}

}

In this example: it's extracting a

java.util.function.Function<Object,Object>

(in this example it a function that get a one parameter)

my question is:

it is possible to run it and get a multi Function Parameter?

how? because (java.util.function ) doesn't have this type

2
  • 1
    Java has BiFunction which accepts 2 arguments Commented Aug 13, 2017 at 14:36
  • pls edit question adding input sample and expected output. I don't see you are providing any Function implementation at all; keeping aside if multiinput function or not ( not like in the stackoverflow link you provide, which is pretty different and provided function implementations). Commented Aug 13, 2017 at 15:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.