Jump to: navigation, search

使用 Drools 5

Drools 5 介绍了硬关键字和软关键字的概念。

硬关键字

硬关键字是保留关键字—在命名域对象、属性、方法、函数和规则文本中使用的其他元素时,不能使用任何硬关键字。 编写规则时,必须避免以下硬关键字列表作为标识符:

  • true
  • false
  • null

软关键字

软关键字仅在它们的上下文中被识别,可以根据需要在其他地方使用这些词,尽管如此,Genesys 仍然建议尽可能避免使用它们以防止混淆。软关键词列表如下:

  • lock-on-active
  • date-effective
  • date-expires
  • no-loop
  • auto-focus
  • activation-group
  • agenda-group
  • ruleflow-group
  • entry-point
  • duration
  • package
  • import
  • dialect
  • salience
  • enabled
  • attributes
  • rule
  • extend
  • when
  • then
  • template
  • query
  • declare
  • function
  • global
  • eval
  • not
  • in
  • or
  • and
  • exists
  • forall
  • accumulate
  • collect
  • from
  • action
  • reverse
  • result
  • end
  • over
  • init

您可用驼峰式大小写形式将这些(硬和软)关键字用作方法名称的一部分,例如 notSomething()accumulateSomething(),这样不会出现任何问题。

转义硬关键字

尽管上述的三个硬关键字不太可能在您现有的域模型中使用,但是如果您绝对需要将它们用作标识符而不是关键字,则 DRL 语言提供了在规则文本中转义硬关键字的功能。要转义一个词,只需用沉音符将其括起来,如下所示:

Holiday( `true` == "yes" ) // 

请注意,Drools 将解决对该方法的引用:

Holiday.isTrue()
This page was last edited on November 22, 2019, at 09:40.
Comments or questions about this documentation? Contact us for support!