jastrachan | 19 Jan 08:37 2005
Picon

Re: How to evaluate a String expression ?

On 19 Jan 2005, at 03:12, Scott Stirling wrote:
> Sorry, man, I missed your point. Yes, you can do this (evaluate() not 
> eval() though):
>
> groovy> expression = '2 * 3'
> groovy> result = evaluate('2 * 3')
> groovy> println "Result = ${result}"
> groovy> go
> Result = 6

Agreed.

The evaluate() function is a helper method available in top level 
scripts (i.e. outside of class methods).

If you are in a class (or indeed inside Java code) you can get the same 
effect via

shell = new GroovyShell()
shell.evaluate("2 * 3")

James
-------
http://radio.weblogs.com/0112098/


Gmane