Last active
December 25, 2015 16:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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