Search code examples
javadrools

Declare new type in drools that extends a class with generic


I have a java class that looks like this (with getters and setters of course):

public class DynamicTransaction<T> implements Serializable {
    private HeaderDTO header;
    private T body;
}

In Drools, I want to declare specific transactions that extend this class. So I'd like to do someting like this:

declare ShopTransaction extends DynamicTransaction<ShopBody>

end

declare ShopBody
    name: String
    modDate: String
    dailyIdx: int
end 

The problem is, that I get this exception:

[ERR 102] Line 15:39 mismatched input '<'

So my question is: Is it even possible to do this type of inheritance in Drools?


Solution

  • Drools hasn't been extended to manage generics.

    You need to write a Java class

    public class ShopTransaction extends DynamicTransaction<ShopBody>
    

    and then you are good to go for writing your rules with ShopTransaction as a pattern.