Print
Language FAQ

Why doesn't the .class reference work?

MVEL does not have a special .class identifier to refer to types like Java. Instead you refer to a class reference simply by it's name. For example, if a method accepts type Class as a parameter you would call it just like this:

In fact, MVEL treats .class as a regular bean property. So by writing String.class the value returned will be an instance of java.lang.Class referring to java.lang.Class itself, since it would be the equivalent of writing String.class.getClass() in Java.

The principle reason for this, is that MVEL has a dynamic type system which treats types as first-class objects, rather than "special" objects like in Java (hence the need for .class). And as such, MVEL allows for class types to be referenced as ordinary variables unlike Java, allowing for type-aliasing.

MVEL does not seem to support creation of arrays using the new keyword, how can I create an array?

MVEL does not currently support the creation of arrays using the new keyword (ie. new String[5]). This will not apply in MVEL 2.0, which will support regular array creation in the same way as Java.

The first method using the simple, inline array syntax like so:

For more information on this see Inline List, Maps and Arrays.

The second method is to use the java.lang.reflect.Array class, which is imported by default in MVEL, using the following syntax:

Note: that the above syntax is not in error, MVEL does not require that you specify .class to refer to class literals.

Powered by Atlassian Confluence