Groovy Documentation

## groovy.util
[Java] Class Eval

    java.lang.Object
      groovy.util.Eval

    public class Eval
    extends java.lang.Object

Allow easy integration from Groovy into Java through convenience methods.
This class is a simple helper on top of GroovyShell. You can use it to evaluate small Groovy scripts that don't need large Binding objects. For example, this script executes with no errors:

     assert 10 == Eval.me(' 2 * 4 + 2')
     assert 10 == Eval.x(2, ' x * 4 + 2')

Authors:
  Dierk Koenig

See Also:
  GroovyShell

Method Summary
`static java.lang.Object` | `me(java.lang.String expression)` Evaluates the specified String expression and returns the result.
`static java.lang.Object` | `me(java.lang.String symbol, java.lang.Object object, java.lang.String expression)` Evaluates the specified String expression and makes the parameter available inside the script, returning the result.
`static java.lang.Object` | `x(java.lang.Object x, java.lang.String expression)` Evaluates the specified String expression and makes the parameter available inside the script bound to a variable named 'x', returning the result.
`static java.lang.Object` | `xy(java.lang.Object x, java.lang.Object y, java.lang.String expression)` Evaluates the specified String expression and makes the first two parameters available inside the script bound to variables named 'x' and 'y' respectively, returning the result.
`static java.lang.Object` | `xyz(java.lang.Object x, java.lang.Object y, java.lang.Object z, java.lang.String expression)` Evaluates the specified String expression and makes the first three parameters available inside the script bound to variables named 'x', 'y', and 'z' respectively, returning the result.

Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Method Detail

### me

    public static java.lang.Object me(java.lang.String expression)

  Evaluates the specified String expression and returns the result. For example:

       assert 10 == Eval.me(' 2 * 4 + 2')

  throws:
    CompilationFailedException if expression is not valid Groovy
  Parameters:
    `expression` - the Groovy expression to evaluate
  Returns:
    the result of the expression

### me

    public static java.lang.Object me(java.lang.String symbol, java.lang.Object object, java.lang.String expression)

  Evaluates the specified String expression and makes the parameter available inside the script, returning the result. For example, this code binds the 'x' variable:

       assert 10 == Eval.me('x', 2, ' x * 4 + 2')

  throws:
    CompilationFailedException if expression is not valid Groovy
  Parameters:
    `expression` - the Groovy expression to evaluate
  Returns:
    the result of the expression

### x

    public static java.lang.Object x(java.lang.Object x, java.lang.String expression)

  Evaluates the specified String expression and makes the parameter available inside the script bound to a variable named 'x', returning the result. For example, this code executes without failure:

       assert 10 == Eval.x(2, ' x * 4 + 2')

  throws:
    CompilationFailedException if expression is not valid Groovy
  Parameters:
    `expression` - the Groovy expression to evaluate
  Returns:
    the result of the expression

### xy

    public static java.lang.Object xy(java.lang.Object x, java.lang.Object y, java.lang.String expression)

  Evaluates the specified String expression and makes the first two parameters available inside the script bound to variables named 'x' and 'y' respectively, returning the result. For example, this code executes without failure:

       assert 10 == Eval.xy(2, 4, ' x * y + 2')

  throws:
    CompilationFailedException if expression is not valid Groovy
  Parameters:
    `expression` - the Groovy expression to evaluate
  Returns:
    the result of the expression

### xyz

    public static java.lang.Object xyz(java.lang.Object x, java.lang.Object y, java.lang.Object z, java.lang.String expression)

  Evaluates the specified String expression and makes the first three parameters available inside the script bound to variables named 'x', 'y', and 'z' respectively, returning the result. For example, this code executes without failure:

       assert 10 == Eval.xyz(2, 4, 2, ' x * y + z')

  throws:
    CompilationFailedException if expression is not valid Groovy
  Parameters:
    `expression` - the Groovy expression to evaluate
  Returns:
    the result of the expression

Groovy Documentation