question
I've searched the web trying to find the solution, but i'm running a bit against the clock so i'm gonna post here as well.
Is there any method or technique in Java (1.5) that allows the evaluation and execution of expressions, much like Javascript's
what i want to do is, store a String
you may ask, "why not use a function to compare those two variables?".. good question. the thing is that we're supposed to support dynamic rules, for instance, i have to be able to insert new rules at any time, simply by adding a line putting a string on the list.
Hope i was clear on my question.
I don't need the exact solution, just point me towards the right direction and i'll appreciate it.
thanks.
*edit*
i've read and looked into every suggestion made by you guys.. and thank you all for those. :) the thing is, this is a school project and i could have gotten into trouble (ie, fail) if i used code from some library unknown to them.. i was looking for a source-code-level solution.. but since i had to turn it in by today, i had to choose another path.
i did this by having an class Rule, with an eval() function.. and then i extended it to RuleABC, Rule123, and so on. Each class had its own eval() method.. it's not exactly what i wanted, but i got it to work.
nevertheless, the links you guys posted were very interesting.. and i'm sure me (and someone else) will make a good use of them in the future.
thanks everyone.
Is there any method or technique in Java (1.5) that allows the evaluation and execution of expressions, much like Javascript's
eval()? what i want to do is, store a String
"var1 < var2" and then, have it executed and then use it in an if-clause. you may ask, "why not use a function to compare those two variables?".. good question. the thing is that we're supposed to support dynamic rules, for instance, i have to be able to insert new rules at any time, simply by adding a line putting a string on the list.
Hope i was clear on my question.
I don't need the exact solution, just point me towards the right direction and i'll appreciate it.
thanks.
*edit*
i've read and looked into every suggestion made by you guys.. and thank you all for those. :) the thing is, this is a school project and i could have gotten into trouble (ie, fail) if i used code from some library unknown to them.. i was looking for a source-code-level solution.. but since i had to turn it in by today, i had to choose another path.
i did this by having an class Rule, with an eval() function.. and then i extended it to RuleABC, Rule123, and so on. Each class had its own eval() method.. it's not exactly what i wanted, but i got it to work.
nevertheless, the links you guys posted were very interesting.. and i'm sure me (and someone else) will make a good use of them in the future.
thanks everyone.
