[rules-users] ClassCast exception while doing retract

Greg Barton greg_barton at yahoo.com
Tue Mar 17 16:49:15 EDT 2009


Are you passing in an array of FactHandles?  If not you can't cast them to FactHandle.  If you're passing in objects that are in WM, you can get their FactHandle by calling WorkingMemory.getFactHandle(Object)

Otherwise, you can either constrain the generic T, or just use an array of FactHandle. (FactHandle is an interface, after all.)  

public static <T extends FactHandle> void remove(WorkingMemory workingMemory, T... array) { 
  if(array == null) return;
  for (T handle : array) {  
    workingMemory.retract(handle);
  } 
}

--- On Tue, 3/17/09, techy <techluver007 at gmail.com> wrote:

> From: techy <techluver007 at gmail.com>
> Subject: [rules-users] ClassCast exception while doing retract
> To: rules-users at lists.jboss.org
> Date: Tuesday, March 17, 2009, 3:04 PM
> Hello,
> My retract util func() is below and ClassCast exception is
> thrown. Some help
> please...
> 
>  public static <T>  void remove(WorkingMemory
> workingMemory,T... array) 
>     { 
>         if(array == null || array.length == 0)
>         {
>             return;
>         }
>     
>         for (int i=0;i<array.length;i++) 
>         { 
>             
>                 workingMemory.retract((FactHandle)
> array[i]); 
>         } 
>              
>     } 
> -- 
> View this message in context:
> http://www.nabble.com/ClassCast-exception-while-doing-retract-tp22566763p22566763.html
> Sent from the drools - user mailing list archive at
> Nabble.com.
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users


      



More information about the rules-users mailing list