Here you can find the source of eval(String expression, Object... arguments)
public static Object eval(String expression, Object... arguments) throws ScriptException
//package com.java2s; //License from project: Apache License import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class Main { public static Object eval(String expression, Object... arguments) throws ScriptException { ScriptEngineManager engineManager = new ScriptEngineManager(); ScriptEngine engine = engineManager.getEngineByName("JavaScript"); for (int i = 0; i < arguments.length; i++) { expression = expression.replaceAll("%" + (i + 1), arguments[i].toString()); }/* w w w. j av a2s . c om*/ return engine.eval(expression); } }