# Class ExpressionFactory

java.lang.Object
jakarta.el.ExpressionFactory

public abstract class ExpressionFactory extends Object
Factory for creating `ValueExpression` and `MethodExpression` instances, and for coercing objects to specific types. Implementations parse and compile EL expressions. Use `newInstance()` to obtain an instance using the standard discovery mechanism.

Since:
  EL 2.1

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ExpressionFactory()`
  Constructs an ExpressionFactory.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract <T> T`
  `coerceToType(Object obj, Class<T> expectedType)`
  Coerce the supplied object to the requested type.
  `abstract MethodExpression`
  `createMethodExpression(ELContext context, String expression, Class<?> expectedReturnType, Class<?>[] expectedParamTypes)`
  Create a new method expression instance.
  `abstract ValueExpression`
  `createValueExpression(ELContext context, String expression, Class<?> expectedType)`
  Create a new value expression.
  `abstract ValueExpression`
  `createValueExpression(Object instance, Class<?> expectedType)`
  Creates a `ValueExpression` that, when evaluated, returns the given instance of the specified type.
  `Map<String,Method>`
  `getInitFunctionMap()`
  Returns a map of function names to `Method` objects representing the standard EL functions that are available by default without explicit registration.
  `ELResolver`
  `getStreamELResolver()`
  Returns an `ELResolver` capable of resolving properties on `InputStream` objects, enabling EL expressions to operate on stream types.
  `static ExpressionFactory`
  `newInstance()`
  Create a new `ExpressionFactory`.
  `static ExpressionFactory`
  `newInstance(Properties properties)`
  Create a new `ExpressionFactory` passing in the provided `Properties`.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ExpressionFactory

    public ExpressionFactory()
    Constructs an ExpressionFactory. Subclasses should invoke this constructor to initialize the base factory state.

- ## Method Details

  - ### newInstance

    public static ExpressionFactory newInstance()
    Create a new `ExpressionFactory`. The class to use is determined by the following search order:
    1. services API (META-INF/services/jakarta.el.ExpressionFactory)
    2. $JRE_HOME/lib/el.properties - key jakarta.el.ExpressionFactory
    3. jakarta.el.ExpressionFactory
    4. Platform default implementation - org.apache.el.ExpressionFactoryImpl
    Returns:
      the new ExpressionFactory

  - ### newInstance

    public static ExpressionFactory newInstance(Properties properties)
    Create a new `ExpressionFactory` passing in the provided `Properties`. Search order is the same as `newInstance()`.
    Parameters:
      `properties` - the properties to be passed to the new instance (might be null)
    Returns:
      the new ExpressionFactory

  - ### createValueExpression

    public abstract ValueExpression createValueExpression(ELContext context, String expression, Class<?> expectedType)
    Create a new value expression.
    Parameters:
      `context` - The EL context for this evaluation
      `expression` - The String representation of the value expression
      `expectedType` - The expected type of the result of evaluating the expression
    Returns:
      A new value expression formed from the input parameters
    Throws:
      `NullPointerException` - If the expected type is `null`
      `ELException` - If there are syntax errors in the provided expression

  - ### createValueExpression

    public abstract ValueExpression createValueExpression(Object instance, Class<?> expectedType)
    Creates a `ValueExpression` that, when evaluated, returns the given instance of the specified type. This is a convenience method for creating a constant value expression without requiring an `ELContext`.
    Parameters:
      `instance` - the constant value to wrap
      `expectedType` - the expected type of the value
    Returns:
      a ValueExpression that returns the given instance when evaluated

  - ### createMethodExpression

    public abstract MethodExpression createMethodExpression(ELContext context, String expression, Class<?> expectedReturnType, Class<?>[] expectedParamTypes)
    Create a new method expression instance.
    Parameters:
      `context` - The EL context for this evaluation
      `expression` - The String representation of the method expression
      `expectedReturnType` - The expected type of the result of invoking the method
      `expectedParamTypes` - The expected types of the input parameters
    Returns:
      A new method expression formed from the input parameters.
    Throws:
      `NullPointerException` - If the expected parameters types are `null`
      `ELException` - If there are syntax errors in the provided expression

  - ### coerceToType

    public abstract <T> T coerceToType(Object obj, Class<T> expectedType)
    Coerce the supplied object to the requested type.
    Type Parameters:
      `T` - The type to which the object should be coerced
    Parameters:
      `obj` - The object to be coerced
      `expectedType` - The type to which the object should be coerced
    Returns:
      An instance of the requested type.
    Throws:
      `ELException` - If the conversion fails

  - ### getStreamELResolver

    public ELResolver getStreamELResolver()
    Returns an `ELResolver` capable of resolving properties on `InputStream` objects, enabling EL expressions to operate on stream types. This allows expressions to read data from input streams using standard property navigation syntax.
    Returns:
      the StreamELResolver, or `null` if not supported by this implementation
    Since:
      EL 3.0

  - ### getInitFunctionMap

    public Map<String,Method> getInitFunctionMap()
    Returns a map of function names to `Method` objects representing the standard EL functions that are available by default without explicit registration. Implementations can override this method to provide a set of built-in functions.
    Returns:
      a map of function names to methods, or `null` if no default functions are provided
    Since:
      EL 3.0