简短版本:如何使用新的KIE API禁用MVEL严格模式?
我知道有一个配置属性"drools.dialect.mvel.strict" 可以使用旧的KnowledgeBuilder API进行设置.但是我找不到用新API实现相同的方法.
长版:我有一个对象方法,叫做Object属性(String name),结果可以是很多不同的类型.有时可能是List,其他字符串或其他什么.现在为了使用该方法,我必须使用大量的cast或drools抛出异常.对于以下示例:
$entity : RootEntity( attribute('authors') != null &&
attribute('authors').size() >= 3 &&
attribute('authors')[2] == 'whatever' )
Run Code Online (Sandbox Code Playgroud)
我得到这样的错误:
Unable to Analyse Expression attribute("authors").size() >= 3:
[Error: unable to resolve method using strict-mode: java.lang.Object.size()]
Unable to Analyse Expression attribute("authors")[2] == "whatever":
[Error: unknown collection type: class java.lang.Object; property=]
Run Code Online (Sandbox Code Playgroud)
为了在启用严格类型的情况下使这项工作,我必须输入相同的表达式:
$entity : RootEntity( attribute('authors') != null &&
((java.util.List) attribute('authors')).size() >= 3 &&
((java.util.List) attribute('authors'))[2] == 'whatever' )
Run Code Online (Sandbox Code Playgroud)
可以使用严格键入选项禁用.
| 归档时间: |
|
| 查看次数: |
1890 次 |
| 最近记录: |