In the service I have
@Inject @Named("testData") Map<Integer, BigDecimal> customerBalances;
In the Module I have
Map<Integer,BigDecimal> map;
binder.bind(map.getClass())
.annotatedWith(new NamedAnnotation("testData"))
.toInstance(customerTotals);
The compiler says
The method toInstance(capture-of ? extends Map) in the type
LinkedBindingBuilder<capture-of ? extends Map> is not applicable for
the
arguments (Map<Integer,BigDecimal>)
Are there any workarounds to solve this ? Or do i need to use non type
safe Maps.
cheers
Andy
bind(new TypeLiteral<Map<Integer, BigDecimal>> { })
.annotatedWith(...)
.toInstance(myMap);
Kludgey as it is, this innovation never ceases to amaze me in its ingenuity. =)
Dhanji.
I am trying to inject some test data into one of my MockServices
In the service I have
@Inject @Named("testData") Map<Integer, BigDecimal> customerBalances;
In the Module I have
Map<Integer,BigDecimal> map;
binder.bind(map.getClass())
.annotatedWith(new NamedAnnotation("testData"))
.toInstance(customerTotals);
The compiler says
The method toInstance(capture-of ? extends Map) in the type
LinkedBindingBuilder<capture-of ? extends Map> is not applicable for
the
arguments (Map<Integer,BigDecimal>)
Are there any workarounds to solve this ? Or do i need to use non type
safe Maps.
cheers
Andy
Put another way, generic types are no different from raw types to the
JVM due to the fact that they are erased to raw types by the compiler
(and only retained in the type reflection).
Dhanji.
Thanks :)
On Nov 14, 12:12 pm, "Stuart McCulloch" <mccu...@gmail.com> wrote: