|
|||||
|
|||||
Useful Things |
MVEL Type Conversion
MVEL is a dynamically typed language (with optional static typing). Since MVEL is built on top of the JVM, which is a strongly typed, it is often necessary for MVEL to provide high-level type conversion. To that end, MVEL provides an open and pluggable type conversion API in order to facilitate this. Out of the box, MVEL comes with a full array of type converters that can handle the entire gambit of Java types, with special support for things like collections and the The org.mvel.DataConversion ClassThe It contains three useful methods: The first two methods are used by the compiler and runtime to actually perform conversions between types. The third method allows you to programmatically register more conversion handler classes. Only one conversion handler can be registered per type. So if you replace the conversion handler for a built-in type, your conversion capabilities will be limited to what you implement in the replacement converter. The org.mvel.ConversionHandler InterfaceThe conversion handler interface has two methods you must implement: Each converter represents a target type for conversion to a particular data type. So in the case of say, an Why It's Needed, and How It's UsedMVEL's typing model is very loose and supports two models of typing: duck typing, and static typing. The model used is inferred by the actual script itself. Let's look an example: In this particular MVEL script, we have declared two variables:
Now this isn't exactly a good example, because who would purposefully pass a string to a method which accepts an int? But it demonstrates the automatic data conversion at work. When MVEL tries to compile It's more likely that you'll be taking advantage of int-to-long and int-to-double type conversions on a regular basis in your scripts, which can be very handy. |
||||
|
Copyright 2003-2006 - The Codehaus. All rights reserved unless otherwise noted.
Powered by Atlassian Confluence
|
|||||