To create a list of objects, enclose a list of expressions in curly braces. As with method arguments, these expressions cannot use the comma operator unless it is enclosed in parentheses. Here is an example:
name in { null,"Untitled" }
This tests whether the name
property is null
or equal to "Untitled"
.
The syntax described above will create a instanceof the List
interface. The exact subclass is not defined.
Sometimes you want to create Java native arrays, such as int[] or Integer[]. OGNL supports the creation of these similarly to the way that constructors are normally called, but allows initialization of the native array from either an existing list or a given size of the array.
new int[] { 1, 2, 3 }
This creates a new int array consisting of three integers 1, 2 and 3.
To create an array with all null
or 0
elements, use the alternative size constructor
new int[5]
This creates an int array with 5 slots, all initialized to zero.
Maps can also be created using a special syntax.
#{ "foo" : "foo value", "bar" : "bar value" }
This creates a Map initialized with mappings for "foo"
and "bar"
.
Advanced users who wish to select the specific Map class can specify that class before the opening curly brace
#@java.util.LinkedHashMap@{ "foo" : "foo value", "bar" : "bar value" }
The above example will create an instance of the JDK 1.4 class LinkedHashMap
, ensuring the the insertion order of the elements is preserved.