Skip to content

Instantly share code, notes, and snippets.

@eduardocl
Last active December 25, 2015 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduardocl/7007046 to your computer and use it in GitHub Desktop.
Save eduardocl/7007046 to your computer and use it in GitHub Desktop.
Executando expressões lógicas criadas dinamicamente em java através da execução de um código javascript dentro do código java.
ScriptEngineManager mgr = new ScriptEngineManager();
String expression = "if( (((((4 == 1) && 'USER_ID' != '1') && 'ON_GOING' == 'ON_GOING') || 1381374000000 != 1381374000000)){ resut = true ; } else { result = false; }"
ScriptEngine jsEngine = mgr.getEngineByName("JavaScript");
boolean result = false;
try {
result = (Boolean) jsEngine.eval(expression);
} catch (ScriptException ex) {
ex.printStackTrace();
}
System.out.println("result = " + result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment