1. When starting container with the below classes (trying to inject implementation of GenericFoo (FooImpl) to field foo in Bar) DeploymentException exception is thrown. {code:java} interface GenericFoo<T extends Comparable<T>> { T someMethod(); }
class FooImpl<T extends Comparable<T>> implements GenericFoo<T> { @Override public T someMethod() { return null; } }
class Bar { @Inject private GenericFoo<Long> foo; }
{code}
CDI Spec 5.2.4. states that a parameterized bean type is considered assignable to a parameterized required type if +the required type parameter is an actual type, the bean type parameter is a type variable and the actual type is assignable to the upper bound, if any, of the type variable.+
From my understanding, the injection should work.
Stacktrace:
{code:java} at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:378) at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:290) at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:143) at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:164) at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:526) at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:64) at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:62) at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62) at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55) at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) at java.util.concurrent.FutureTask.run(FutureTask.java) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) {code}
2. More comlex case
CDI Spec 5.2.4. states that a parameterized bean type is considered assignable to a parameterized required type if +the required type parameter and the bean type parameter are both type variables and the upper bound of the required type parameter is assignable to the upper bound, if any, of the bean type parameter+
So, TwoKeyHashMap should be injected into Bar. {code:java} class TwoKeyHashMap<K1, K2, V extends TwoKeyHashMap.TwoKeyValue<K1, K2>> extends HashMap<K1, V> { public interface TwoKeyValue<K1, K2> { K1 getKey1();
K2 getKey2(); } }
class Value implements TwoKeyHashMap.TwoKeyValue<String, Integer> { @Override public String getKey1() { return "1"; }
@Override public Integer getKey2() { return 2; } }
class Bar { @Inject private TwoKeyHashMap<String, Integer, Value> injected; } {code} |
|