I think there may be a few issues with generics and Java 5 with the JDT
compiler (certainly is with janino) and the way we are using it.

Can you attach this to a JIRA? Our efforts have all been on JDK
1.4compatability to date (I don't even use JDK 5 other then to test
yet - alas
!).



On 5/12/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

Hi
I am having trouble compiling my .drl file using parameterized types. Is
this a known issue or am I doing something wrong?

I have defined a Price class like this:

public class Price<T extends Comparable<T>> implements IPrice<T> { ... }

I have a Product class that has a field of type Price<Money>.

In my Drools client, I instantiate it like this:

product2.setRetailPrice(new Price<Money>(Money.createUSDollars(19.95)));

That's fine. Here is a snippet from my .drl:

rule "Test Type Param"
        no-loop true
        when
                product : IMarketableProduct(productCode == 28014)

        then
                System.out.println("Match!");
                Money fiveDollars = Money.createUSDollars(5);
                Price<Money> addFiveDollars = new Price<Money>(
product.getRetailPrice().getValue().add(fiveDollars));
                product.setRetailPrice(addFiveDollars);
end

The addition of the $5 works fine from a regular Java class. But I get a
few related errors when compiling the above .drl.

Here's the first:
"Syntax error, parameterized types are only available if source level is
5.0"

But I know that Eclipse is using JDK 5. To prove it, here is a copy from
"Configuration Details":
java.class.version=49.0
java.endorsed.dirs=C:\Program Files\Java\jre1.5.0\lib\endorsed
java.ext.dirs=C:\Program Files\Java\jre1.5.0\lib\ext
java.home=C:\Program Files\Java\jre1.5.0
java.io.tmpdir=C:\TEMP\
java.library.path=C:\WINDOWS\system32
;.;C:\WINDOWS\system32;C:\WINDOWS;c:\files\tools\ruby\bin;c:\Program
Files\j2sdk1.4.2_06;C:\Program Files\Java\jdk1.5.0;C:\Program Files\Apache
Software Foundation\Maven 1.0\bin;E:\Program

Files\Inprise\AppServer\bin;C:\WINDOWS\system32;C:\WINDOWS;E:\PROGRA~1\IBM\CLIENT~1;E:\PROGRA~1\IBM\CLIENT~1\Shared;E:\PROGRA~1\IBM\CLIENT~1\Emulator;C:\Program
Files\Microsoft SQL
Server\80\Tools\BINN;C:\Files\AppServer\bin;.;C:\Program Files\Apache
Software Foundation\Maven
1.0\bin;C:\WINNT\system32;C:\WINNT;C:\Files\downloads\JavaCC\javacc-
4.0\bin
java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition
java.runtime.version=1.5.0-b64

I also have tested my rules with an enum, and it worked fine. So Drools
must know that the source really is 5.0.

I checked the settings to double check that everything is set to JDK 5.

I am using the Jboss Rules plugin: drools-ide-3.0-RC-2-bin.zip

I am using eclipse-SDK-3.2RC3-win32.zip

Here is the second related error:

"The type Price is not generic; it cannot be parameterized with arguments
<Money>"

Clearly it is generic, and there is not another Price class I am using.
(My import is correct and there's no other Price on the cp).

Finally, to prove that Drools knows about the correct Price class, here is
the 3rd related compiler error:

"The method add(Money) is undefined for the type Comparable"
So Drools apparently is picking up the Price class, as Price is
parameterized on <T extends Comparable<T>>

That means that Drools loads the correct class because it can see the
upper bound of the type parameter (Comparable).
I have been using this Price class for months in many contexts and it
works great. It is not an issue with the class itself.

Am I doing something wrong? Can we not use parameterized types yet? I
looked at Jira and didn't see anything about this.

Thank you very much for your help
Eben


Reply via email to