Search code examples
javajbossdrools

Casting object to declared type in drools RHS


I've got my declared type as follow:

declare MyType
 myField: String
end 

Now I'm getting a list of myType from a globals. I need to cast the object that is coming from the globals to MyType. Is there a way to do this??


Solution

  • If you need to use your declared classes outside your DRL files, then I would recommend you to declare them as Java classes.

    There is a way to work with these type of objects in Java and that is done using reflection through the KieBase.getFactType(String package, String name) method.

    Hope it helps,