HelenBlack / lambdaj

Automatically exported from code.google.com/p/lambdaj
Apache License 2.0
0 stars 0 forks source link

ConstructorArgumentConverter / project can't take enum as argument. #95

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Use ConstructorArgumentConverter with a class who's constructor takes an 
enum.  (I'm really not sure if the enum is the problem.  Just a guess.)

What version of the product are you using? On what operating system?
2.4 on Linux, JDK 6.

Please provide any additional information below.

I'm sorry for not providing a detailed example, so I will understand if the 
issue will be rejected.  

Here is my call:

List<GenericPRB> genPrbList = convert(prbList, new 
ConstructorArgumentConverter<PRB, GenericPRB>(GenericPRB.class, on(PRB.class), 
az));

The GenericPRB class's constructor takes a PRB and an enum (az in this case). 

Here is the stack trace:

FAILED: TestGetAvgPrbList
ch.lambdaj.function.argument.ArgumentConversionException: Unable to convert the 
placeholder AZ in a valid argument
    at ch.lambdaj.function.argument.ArgumentsFactory.actualArgument(ArgumentsFactory.java:92)
    at ch.lambdaj.function.convert.ArgumentConverter.<init>(ArgumentConverter.java:29)
    at ch.lambdaj.function.convert.ConstructorArgumentConverter.<init>(ConstructorArgumentConverter.java:35)

I get the same error if I try to use 'project':

List<GenericPRB> genPrbList = project(prbList, GenericPRB.class, on(PRB.class), 
az);

Until this is fixed (if it is indeed a bug), I've found a work around by 
writing my own special converter class.

Original issue reported on code.google.com by gdwar...@gmail.com on 7 Jun 2012 at 3:12

GoogleCodeExporter commented 8 years ago
Is this issue due to the known limitations? 
http://code.google.com/p/lambdaj/wiki/KnownLimitations

I was hoping since the enum (final class) wasn't being used with on(), it would 
be okay.

Original comment by gdwar...@gmail.com on 7 Jun 2012 at 3:17

GoogleCodeExporter commented 8 years ago
You cannot use the ConstructorArgumentConverter<F,T> in this way. It is 
supposed to convert an instance of the class F into an instance of the T by 
invoking a constructor of the class T passing to it some values taken from the 
fields of F as in the following example:

new ConstructorArgumentConverter<PRB, GenericPRB>(GenericPRB.class, 
on(PRB.class).getValue1(), on(PRB.class).getValue2(), ...);

You cannot use in this converter values that are not taken from the F instance.

Original comment by mario.fu...@gmail.com on 8 Jul 2012 at 1:49