''Unable to find Class' error in Drools

im trying to define a simple function in drools :

function void difference(List<String> fileOld, List<String> fileNew)
{

   ArrayList<String> add = new ArrayList<String>(fileNew);
   add.removeAll(fileOld);
   System.out.println("files Added: " + add);

   ArrayList<String> remove = new ArrayList<String>(fileOld);
   remove.removeAll(fileNew);
   System.out.println("files Removed: " + remove);
 }   

but it says Unable to resolve type List while building function. java.lang.ClassNotFoundException: Unable to find class 'List' ] Cannot make a static reference to the non-static method getFileOld() from the type FileData Cannot make a static reference to the non-static method getFileNew() from the type FileData

My rules are:

rule "files are equal"

when 
    FileData(fileOld == fileNew)        

then
   System.out.println("files are equal");
end

rule "files not equal"
when
    not FileData(fileOld == fileNew)
then
   System.out.println("files are not equal");
   difference(FileData.getFileOld(),FileData.getFileNew()); 
end

fileOld and fileNew are the list of filenames in a folder at two different instances. im trying to find the difference between fileOld and fileNew and display the list of files added/deleted.



Solution 1:[1]

In DRL, the situation is very much as it is in Java. You use either "import" or the full class name:

import java.util.List
import java.util.ArrayList



function void difference(java.util.List<String> fileOld, 
                         java.util.List<String> fileNew)

It doesn't hurt to read the Drools documentation.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 laune