简体   繁体   English

Java Drools对象分配是否带有冒号?

[英]Java Drools Object Assignment With a Colon?

I'm learning Java and Drools so that i can edit an existing codebase, I've encountered some syntax i believe is simply assigning a variable/object but i'm uncertain and i'd appreciate some clarity and insight before i incorrectly apply and rely on it. 我正在学习Java和Drools,以便可以编辑现有的代码库,遇到了一些语法,我相信这只是在分配变量/对象,但是我不确定,在我错误地应用和依靠它。

RULE "Rule1"

    WHEN
        result : Result()   
        policy : Policy()   

    THEN
        logger.info("Running Rule1");
        retract(result);
END

It's the "xxx : xxx()" bit i'm uncertain about.. i try searching, but i end up with static declaration etc 这是我不确定的“ xxx:xxx()”位。我尝试搜索,但最终以静态声明等结尾

is it the same as "xxx = new xxx();" 是否与“ xxx = new xxx();”相同? or "xxx : xxx();" 或“ xxx:xxx();” ?

My previous coding experience is with PHP and C#, thanks. 我以前的编码经验是使用PHP和C#,谢谢。

A pattern element is the most important Conditional Element. 模式元素是最重要的条件元素。 It can potentially match on each fact that is inserted in the working memory. 它可以潜在地匹配插入工作内存中的每个事实。

A pattern contains of zero or more constraints and has an optional pattern binding. 模式包含零个或多个约束,并具有可选的模式绑定。

[ patternBinding : ] pattern type ( [ constraints ] ) [ patternBinding ] 模式类型 [ 约束 ]

In its simplest form, with no constraints, a pattern matches against a fact of the given type. 在没有约束的最简单形式中,模式与给定类型的事实匹配。 In the following case the type is Person, which means that the pattern will match against all Person objects in the Working Memory: 在以下情况下,类型为Person,这意味着模式将与工作内存中的所有Person对象匹配:

Person()

For referring to the matched object, use a pattern binding variable such as $p. 要引用匹配的对象,请使用模式绑定变量,例如$ p。 (The '$' is not mandatory, just a convention.) (“ $”不是强制性的,只是一个约定。)

$p: Person()

A property can be bound to a variable: 属性可以绑定到变量:

Person( $firstAge : age ) // binding

Just note that "binding" isn't "assigning"; 请注意,“绑定”不是“分配”; a "binding variable" isn't a "variable" as it is known in C# or PHP. “绑定变量”不是C#或PHP中已知的“变量”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM