Closed ratcashdev closed 3 years ago
consider the following test snippet:
import io.micronaut.context.ApplicationContext; import io.micronaut.context.annotation.Bean; import io.micronaut.context.annotation.Factory; import java.util.AbstractCollection; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Optional; import javax.inject.Inject; import javax.inject.Singleton; import static org.junit.Assert.assertNotNull; import org.junit.Test; public class GenericInjectionTest { public static class MyContainer<T> extends AbstractCollection<T>{ List<T> data; public MyContainer() { this.data = new ArrayList<>(); } @Override public Iterator<T> iterator() { throw new UnsupportedOperationException("Not supported yet."); } @Override public int size() { throw new UnsupportedOperationException("Not supported yet."); } } @Factory public static class MyFactory { @Bean public MyContainer<String> constructContainer() { return new MyContainer<>(); } } @Singleton public static class ContainerUser { @Inject MyContainer list1; @Inject MyContainer<String> list2; } @Test public void testInjection() { try (ApplicationContext ctx = ApplicationContext.run()) { Optional<ContainerUser> bean = ctx.findBean(ContainerUser.class); assertNotNull(bean.get().list1); // fails here assertNotNull(bean.get().list2); }; } }
Test should be successful.
bean.get().list2 is null. It will not be null if the MyContainer would not implement AbstractCollection or Collection<E> for that matter.
bean.get().list2
null
MyContainer
AbstractCollection
Collection<E>
Initial related discussion: https://gitter.im/micronautfw/questions?at=5f1934b321f5e643aa43e442
bean collections are supported in 3.0
Steps to Reproduce
consider the following test snippet:
Expected Behaviour
Test should be successful.
Actual Behaviour
bean.get().list2
isnull
. It will not be null if theMyContainer
would not implementAbstractCollection
orCollection<E>
for that matter.Environment Information