[rules-users] MVEL strict mode -- when, why?

Barry Kaplan groups1 at memelet.com
Wed Jun 9 14:27:48 EDT 2010


>From the MVEL docs (http://mvel.codehaus.org/MVEL+2.0+Typing):

Strict Typing

Strict typing in MVEL is an optional mode for the compiler, in which all
types must be fully qualified, either by declaration or inference.

Enabling Strict Mode
When compiling an expression, the compiler can be put into strict mode
through the ParserContext by setting setStrictTypeEnforcement(true).

Satisfying type strictness can be accomplished both by requiring explicit
declaration of types inside the expression, or by notifying the parser ahead
of time of what the types of certain inputs are.

For example:

ExpressionCompiler compiler = new ExpressionCompiler(expr);

ParserContext context = new ParserContext();
context.setStrictTypeEnforcement(true);

context.addInput("message", Message.class);
context.addInput("person", Person.class);

compiler.compile(context);

In this example we inform the compiler that this expression will be
accepting two external inputs: message and person and what the types of
those inputs are. This allows the compiler to determine if a particular call
is safe at compile time, instead of failing at runtime.
	Note about Generic Types
You must use Strong Typing Mode to enable awareness of generic types. Type
parameters for collections and other types will not be visible in
strict-typing mode alone.
Strong Typing

Strong typing is a newly introduced mode in MVEL 2.0. It is different from
strict mode in the sense that strongly typed mode requires that all
variables be type qualified. Contrast this with strict mode which only
requires that properties and method calls be qualified at compile-time.

See the full article: Strong Typing Mode 
-- 
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/MVEL-strict-mode-when-why-tp95666p883155.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list