Interface ExprEvaluator<T>

Type Parameters:
T - The return type that is needed by the caller
All Known Implementing Classes:
GraalJsEvaluator

public interface ExprEvaluator<T>

An evaluator is a scripting helper that knows what its return type will be at runtime. You can create an Evaluator from an environment and a desired return type, then reuse it. Primitive types that can be mapped from the script to the return type should, including

  • Double -> Long
  • Double -> Integer
  • Double -> Float
  • Long -> Integer

An evaluator is not threadsafe by default. If you need threadsafe evaluators with similar semantics, wrap it in a ThreadLocal.

  • Method Details

    • eval

      T eval()
      Evaluate the provided script, returning the value that it yields
      Returns:
      An object of type T
    • script

      ExprEvaluator<T> script(String scriptText)
      Parameters:
      scriptText - script text
      Returns:
      this ExprEvaluator, for method chaining
    • put

      ExprEvaluator<T> put(String varName, Object var)
      Set the variable environment of the evaluator
      Parameters:
      varName - the variable name to add to the environment
      var - the object to bind to the varname
      Returns:
      this ExprEvaluator, for method chaining
    • put

      default ExprEvaluator<T> put(Object... vars)