Print
Inline List, Maps and Arrays

MVEL allows you to express Lists, Maps and Arrays using simple elegant syntax. Consider the following example:

This is functionally equivalent to the following code:

This can be a very powerful way to express data structures inside of MVEL. You can use these constructs anywhere, even as a parameter to a method:

Lists

Lists are expressed in the following format: [item1, item2, ...]

For example:

Maps

Maps are expressed in the following format: [key1 : value1, key2: value2, ...]

For example:

Arrays

Arrays are expressed in the following format: {item1, item2, ...}

For example:

Array Coercion

One important facet about inline arrays to understand is their special ability to be coerced to other array types. When you declare an inline array, it is untyped, but say for example you are passing to a method that accepts int[]. You simply can write your code as the following:

In this case, MVEL will see that the target method accepts an int[] and automatically type the array as such.

Powered by Atlassian Confluence