G
G
Gfd2016-06-07 15:10:08
Java
Gfd, 2016-06-07 15:10:08

I have code text in a String variable. Can it be done?

There is a String code variable; it contains the code of one method. Can it be done with some libraries or some other way? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Kornachev, 2016-06-07
@Gfd

java has the ability to execute the code of some scripting languages. eg: javascript, groovy (scripting language for JVM).
Just like that, java code cannot be executed on the fly in a line.

V
Vyacheslav, 2016-06-07
@Firik67

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
Object result = engine.eval("4*5");
From here stackoverflow.com/questions/2605032/is-there-an-ev...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question