boolean - Java: Use String as part of source code -


this question has answer here:

today have question had on mind years now.
consider have following evaluation in java:

new evaluationlistener(){       public boolean evaluate(boolean[] b){         return b[0] || b[1];     } } 

i using code in program evaluating terms of different boolean values of b[0] , b[1], doesn't matter @ here.
at moment writing evaluations source code, let program run , watch result in command line.
now wondering how implement evaluation command line. able enter evaluation term command line, read bufferedreader etc. instead of writing source code.

is there way so? thought possible using sort of variable aliases $b0$. how can pass logical or , and , not program?

thanks answer

here's example of expression evaluation java's script api:

scriptenginemanager scriptenginemanager = new scriptenginemanager();  scriptengine scriptengine = scriptenginemanager.getenginebyname("ecmascript"); scriptengine.put("b1", true); scriptengine.put("b2", false);  system.out.println(scriptengine.eval("b1 || b2")); system.out.println(scriptengine.eval("b1 && b2")); 

when run, code prints:

true false 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -