[rules-users] How to handle generics in Drools?

Edson Tirelli ed.tirelli at gmail.com
Mon Oct 17 10:18:18 EDT 2011


   Geoffrey is correct. Java erasure makes it impossible to match objects
based on generic types. It is also a best practice anyway to not use general
purpose collections as your business entities in your business model. Best
to use a properly defined business entity and then the generics issue is not
really an issue.

   Edson

2011/10/17 Geoffrey De Smet <ge0ffrey.spam at gmail.com>

> **
> Java's generics are implemented by erasure,
> which implies that there no information available at runtime that a
> instance of a List is of a certain generic type, for example Boost.
> So I don't think this is possible.
>
> Note that some things do work in erasure IIRC, like the generic type of a
> defined field in a class is available at runtime:
> public class Foo {
>   private List<Bar> list;
> }
> but that's not useful in this case :)
>
> Op 17-10-11 11:30, Martin A schreef:
>
> Hello,
>
>  In my rules file I'd like to set something like this:
>
>  rule "mayThrowDice"
>     when
>         $user : User($gp : gameplay)
>         $gameplay(this == $gp)
>     then
>         exists List<Boost>() {
>             ..... some business logic
>         }
> end
>
>  But it looks like there is no generics support. How can I make sure there
> is a List of type Boost inserted into the session?
>
>  Thank you,
> Martin
>
>
> _______________________________________________
> rules-users mailing listrules-users at lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users
>
>
> --
> With kind regards,
> Geoffrey De Smet
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>


-- 
  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20111017/e785ffaa/attachment.html 


More information about the rules-users mailing list