What is Mvel dialect in Drools?

前端 未结 5 1944
无人及你
无人及你 2021-01-02 16:21

I am new to Drools. I am creating a rule but I get a compile time error

\"field is not visible\'.

I\'ve tried to check with Jbo

5条回答
  •  生来不讨喜
    2021-01-02 17:05

    mvel, or the MVFLEX Expression Language has a rich syntax, many of which allow for more concise and expressive code (and less imperative) than java, e.g.

    • Shorthand for get()ters / set()ters (e.g. encapsulating private fields) to be accessed in an alternative property style syntax (similar to VB or C# properties in .Net)

    ie. instead of

    myObject.setSomeField("SomeValue");
    int x = myObject.getSomeIntField();
    

    You can use the syntax (note the subtle capitalization switch as well):

    myObject.someField = "SomeValue"
    x = myObject.someIntField // Type inferrence
    
    • The return statement is optional (a convention found in many functional languages like Scala), as is the semi-colon, unless you have multiple statements per line:

    x  // i.e. return x;
    
    • Shorthand array creation and indexing by ordinal

    foos = {2, 4, 6, 8, 10}
    foos[3] // foos.get(3)
    
    • Similarly for Maps (Dictionaries)

    bars = ["a" : "Apple", "b" : "Basket"] // Hashmap, with put
    bars["a"]
    bars.a // Similar to dynamically typed object e.g. in javascript, if key is a string.
    
    • Null Safe navigation operator (like the null-conditional operator in Rosyln)

    foo.?bar.baz // if (foo.bar != null) { return foo.bar.baz; } else { return null; }
    

提交回复
热议问题