Skip to end of metadata
Go to start of metadata

MVEL allows the definition of native functions with either the def or function keywords.

Functions are defined in-order of declaration, and cannot be foreword referenced. The only exception to this is within functions themselves, it is possible to forward reference another function.

A Simple Example

Defining a Simple Function

This defines a simple function called "hello" that accepts no parameters. When called it prints "Hello!" to the console. An MVEL-defined function works just like any regular method call, and resolution preference is to MVEL functions over base context methods.

Accepting Parameters and Returning Values

Functions can be declared to accept parameters, and can return a single value. Consider the following example:

This function will accept two parameters (a and b) and then adds the two variables together. Since MVEL uses the last-value-out principle, the resultant value will be returned. Therefore, you can use the function as follows:

The return keyword can also be used to force a return a value from within the internal program flow of the function.

Closures

MVEL allows closures. However the functionality is not interoperable with native Java methods.

See Also

Labels
  • None