Daniel Wellman
2008-11-25 01:05:27 UTC
Has the behavior of CollectionComponentParameter changed now that Pico 2
recognizes generic collection parameter types?
In the example below, I expected that adding a CollectionComponentParameter
with a componentValueType of Cod.class would only have Cod fish in the bowl,
but I observe that it gets both Cod and Shark.
If I repeat the experiment by making the Bowl have a type-erased List, the
test works as I expect -- I only get a Cod.
Is this the expected behavior for typed collections?
Test below:
public void testRegisteringSubsetOfGenericCollectionParameters() {
DefaultPicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Cod.class);
pico.addComponent(Shark.class);
pico.addComponent(GenericBowl.class, GenericBowl.class,
new CollectionComponentParameter(Cod.class, false));
GenericBowl bowl = pico.getComponent(GenericBowl.class);
// FAILS with PicoContainer 2.7-SNAPSHOT, returns 2
assertEquals(1, bowl.fishes.size());
}
// Types
public static interface Fish {
}
public static class Cod implements Fish {
}
public static class Shark implements Fish {
}
public static class GenericBowl {
List<Fish> fishes;
public GenericBowl(List<Fish> fishes) {
this.fishes = fishes;
}
}
... but this one passes:
public void testRegisteringSubsetOfTypeErasedCollectionParameters() {
DefaultPicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Cod.class);
pico.addComponent(Shark.class);
pico.addComponent(GenericBowl.class, GenericBowl.class,
new CollectionComponentParameter(Fish.class, false));
GenericBowl bowl = pico.getComponent(GenericBowl.class);
assertEquals(2, bowl.fishes.size());
assertTrue(CollectionUtilities.contains(bowl.fishes, new
ContainsInstanceOfTypePredicate(Cod.class)));
assertTrue(CollectionUtilities.contains(bowl.fishes, new
ContainsInstanceOfTypePredicate(Shark.class)));
}
public static class TypeErasedListBowl {
List fishes;
public TypeErasedListBowl(List fishes) {
this.fishes = fishes;
}
}
recognizes generic collection parameter types?
In the example below, I expected that adding a CollectionComponentParameter
with a componentValueType of Cod.class would only have Cod fish in the bowl,
but I observe that it gets both Cod and Shark.
If I repeat the experiment by making the Bowl have a type-erased List, the
test works as I expect -- I only get a Cod.
Is this the expected behavior for typed collections?
Test below:
public void testRegisteringSubsetOfGenericCollectionParameters() {
DefaultPicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Cod.class);
pico.addComponent(Shark.class);
pico.addComponent(GenericBowl.class, GenericBowl.class,
new CollectionComponentParameter(Cod.class, false));
GenericBowl bowl = pico.getComponent(GenericBowl.class);
// FAILS with PicoContainer 2.7-SNAPSHOT, returns 2
assertEquals(1, bowl.fishes.size());
}
// Types
public static interface Fish {
}
public static class Cod implements Fish {
}
public static class Shark implements Fish {
}
public static class GenericBowl {
List<Fish> fishes;
public GenericBowl(List<Fish> fishes) {
this.fishes = fishes;
}
}
... but this one passes:
public void testRegisteringSubsetOfTypeErasedCollectionParameters() {
DefaultPicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Cod.class);
pico.addComponent(Shark.class);
pico.addComponent(GenericBowl.class, GenericBowl.class,
new CollectionComponentParameter(Fish.class, false));
GenericBowl bowl = pico.getComponent(GenericBowl.class);
assertEquals(2, bowl.fishes.size());
assertTrue(CollectionUtilities.contains(bowl.fishes, new
ContainsInstanceOfTypePredicate(Cod.class)));
assertTrue(CollectionUtilities.contains(bowl.fishes, new
ContainsInstanceOfTypePredicate(Shark.class)));
}
public static class TypeErasedListBowl {
List fishes;
public TypeErasedListBowl(List fishes) {
this.fishes = fishes;
}
}
--
View this message in context: http://www.nabble.com/CollectionComponentParameter-works-differently-with-generic-Collection-types--tp20673363p20673363.html
Sent from the NanoContainer - PicoContainer - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
View this message in context: http://www.nabble.com/CollectionComponentParameter-works-differently-with-generic-Collection-types--tp20673363p20673363.html
Sent from the NanoContainer - PicoContainer - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email