Java 无法使用对象类型为的严格模式解析方法

Java 无法使用对象类型为的严格模式解析方法,java,drools,strict-mode,Java,Drools,Strict Mode,昨天我问了一个关于严格模式的问题,当把不同类型的参数传递给一个函数时,劳恩找到了一个解决方案。根据建议,我现在使用drools 5.6版 现在,我仍然有严格模式错误,但对于另一种情况。不幸的是,我不能应用相同的解决方案。函数creerAction()返回不同类型的对象。有人对那个案子有想法吗 这里是错误 Unable to Analyse Expression $noeud = creerAction($action,"EvaluerMessageActivable",drools); $act

昨天我问了一个关于严格模式的问题,当把不同类型的参数传递给一个函数时,劳恩找到了一个解决方案。根据建议,我现在使用drools 5.6版

现在,我仍然有严格模式错误,但对于另一种情况。不幸的是,我不能应用相同的解决方案。函数creerAction()返回不同类型的对象。有人对那个案子有想法吗

这里是错误

Unable to Analyse Expression $noeud = creerAction($action,"EvaluerMessageActivable",drools); $action.noeud = $noeud;
    $noeud.prochaineActionSiBlocage = obtenirValeurParametre($noeud.prochaineActionSiBlocage, "CN_Raccrocher");
    $noeud.message = obtenirValeurParametre($noeud.message, '$MessageUrgenceGlobal'):
[Error: unable to resolve method using strict-mode: java.lang.Object.prochaineActionSiBlocage()]
[Near : {... $noeud.prochaineActionSiBlocage = obt ....}]
[Line: 34, Column: 0] : [Rule name='Row 1 DT-625 Evaluer blocage general']
这是我的口水档案

package com.desjardins.gtd.dpsccc.routage.vpa.actionsdialogue

import org.drools.spi.KnowledgeHelper;

function Object creerAction(Action actionCourante, String type, KnowledgeHelper drools) {
    if(actionCourante.getNoeud()!=null){
        String nomActionCourante = actionCourante.getNoeud().getClass().getSimpleName(); 
        if(!nomActionCourante .equals(type)) 
            throw new RuntimeException("Ne peut pas redéfinir le type de " + actionCourante.getNom() + ". Le type était: " + nomActionCourante + " spécifié: " + type);
        return actionCourante.getNoeud();
    }
    else if("EvaluerMessageActivable".equals(type)) return new EvaluerMessageActivable();
    else if("Terminer".equals(type)) return new Terminer();

    return null;
}

declare Action
    nom: String
    noeud: java.lang.Object
    compteur: Integer
end 

declare EvaluerMessageActivable
    message: String
    prochaineActionSiBlocage: String
end 

declare Terminer
    nom: String
end 

rule "Row 1 DT-625 Evaluer blocage general"
salience 100079 
    agenda-group "level0"
    dialect "mvel"
    when
        $action:Action(nom =='EM_UrgenceGlobal')
    then
        $noeud = creerAction($action,'EvaluerMessageActivable',drools); $action.noeud = $noeud
        $noeud.prochaineActionSiBlocage = obtenirValeurParametre($noeud.prochaineActionSiBlocage, 'CN_Raccrocher')
        $noeud.message = obtenirValeurParametre($noeud.message, '$MessageUrgenceGlobal')
end
谢谢您的帮助。

这行代码

$noeud = creerAction(...);
CreeAction
的返回值指定给未声明的变量。由于函数返回
java.lang.Object
,因此使用

Object $noeud = creerAction(...);
来解决这个问题。当然,
$noeud
的后续使用可能必须使用强制转换,以允许编译器找到正确的方法或其他方法


不要认为Drools或MVEL废除了Java的所有类型系统。(Dieu merci!)

在我的测试中,我使用的是Jetty版本6.1.26,该版本有流口水的问题。我试过8.1.2版,效果很好

我还禁用了严格模式:
set属性(“drools.dial.mvel.strict”、“false”)

我对$noeud=creerAction()没有问题。问题是当我尝试使用该对象的属性时(例如:$noeud.prochaineActionSiBlocage)。我尝试了
Object$noeud=creetraction()
EvaluerMessageActivable$noeud=creetraction()
,结果相同。要点是对象(显式或隐式)切断了所有类型信息,没有编译器允许将某个类的字段或方法与仅仅是对象类型的对象一起使用。(在《法国专利法》一书中)这是一个很好的例子,它是生产函数中最重要的部分。这是一个规则编写引擎。Tout deux roule drools 5.2版。我不同意你的看法。