Status: New
Owner: ----
New issue 564 by dean.hiller: binding to a generic and fix for it too...
http://code.google.com/p/google-guice/issues/detail?id=564
short path to fix....
line 275 in TypeLiteral.java (function getFieldType(Field field)
change field.getGenericType() and instead call field.getType() and then
everything works. Below is more detail on the bug though...
In InjectionPoint.java, there is the key lookup
key = Annotations.getKey(type.getFieldType(field), field, annotations,
errors);
type.getFieldType(field) makes a call to field.getGenericType
so in a unit test, I have
@Inject
private MockSimpleEditAddGridFactory<EPWFormularyMsg> mockFactory;
If I erase the <EPWFormularyMsg> part, my unit test passes(and the
injection is correct). If I put it back, the unit test fails(because
injection is wrong).....very odd considering generics are supposedly erased
at runtime but read on....
In my binding(which won't work because field.getGenericType is different
then the class I am binding here and different then
field.getType())....(field.getGenericType returns not just the class but
the generic <EPWFormularyMsg> as well!!! so it can't find this binding from
below)
b.bind(SimpleEditAddGridFactory.class).to(MockSimpleEditAddGridFactory.class);
b.bind(MockSimpleEditAddGridFactory.class).in(Singleton.class);
If field.getGenericType where changed to field.getType(), my stuff would
work again!!!!
The other option, is I could try to create my own Key by getting the class
and then getting the field and calling field.getGenericType to pass to the
Key...that is such a pain....I should just be able to bind the types.
unless there is a way that I have not seen to bind generics somehow???
I have tried creating a class object like this but naturally the compiler
complains on this one...(and the generics would be erased I think too
unlike the field which is capturing generics)...
Class<MockSimpleEditAddGridFactory<EPWFormularyMsg>> inst =
MockSimpleEditAddGridFactory.class;
thanks,
Dean
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en.