Print
MVEL 2.0 Language FAQ

Why doesn't the .class reference work?

MVEL does not have a special .class identifier to refer to type literals like Java. There are no class literals per se. 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 regular variables, rather than qualified type-literals like in Java. And as such, MVEL allows for class types to be referenced as ordinary variables unlike Java, allowing for type-aliasing.

Why can't I write object.class.name?

This is a limitation which may be addressed in a future version of MVEL, but bean properties are not supported against Class references. This does not mean that you cannot call methods of Class, but that you must use full qualified method calls like:

This limitation is completely limited to java.lang.Class as a consequence of property-resolution orders and the way that MVEL deals with class references.

Powered by Atlassian Confluence