Hi Bill,
In your example, the raw types of both the producer and consumer are both identical, so,
like you say, we need to consider the type parameters.
* the type of the producer is resolved to have a single type parameter, which is a type
variable with upper bound MediumClass.
* the required type for s1 has a single type parameter, which is an actual type
SmallClass
* the required type b1 has a single type parameter, which is an actual type BigClass
* BigClass is assignable to MediumClass
* SmallClass is NOT assignable to MediumClass
Therefore, like you say, for s1:
* The REQUIRED type parameter is an ACTUAL TYPE (yes, it's SmallClass)
* the BEAN type parameter is a TYPE VARIABLE (yes, it has upper bound MediumClass)
* and the ACTUAL TYPE is ASSIGNABLE TO the upper bound, if any, of the TYPE VARIABLE (no,
SmallClass is not assignable to MediumClass)
and for b1:
* The REQUIRED type parameter is an ACTUAL TYPE (yes, it's BigClass)
* the BEAN type parameter is a TYPE VARIABLE (yes, it has upper bound MediumClass)
* and the ACTUAL TYPE is ASSIGNABLE TO the upper bound, if any, of the TYPE VARIABLE (yes,
BigClass is assignable to MediumClass)
And yes, looking at this, it does seem the wrong way around.
Gavin, your thoughts?
On 30 Jul 2010, at 17:49, Bill Wigger wrote:
In section 5.2.3 the spec seems to be misworded with respsect to
"assignable to" and "assignable from".
The start of this section states (capitalization addded):
"A parameterized BEAN TYPE is considered ASSIGNABLE TO a parameterized REQUIRED TYPE
if they have identical raw type and for each parameter:"
and then it list as one of the cases:
"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"
This seems to state that a Bean Type is assignable to a Required Type if ... the Required
type is assignable to the upper bound of the Bean Type. This seems to then be
contradicting itself, and the reading of that second part should be:
"the required type parameter is an actual type, the bean type parameter is a type
variable and the actual type is ASSIGNABLE FROM the upper bound, if any, of the type
variable"
The question comes down which injection below is valid:
public class C1<T extends MediumClass> {
@Produces ... ArrayList<T> m1()
@Inject ... ArrayList<SmallClass> s1;
@Inject ... ArrayList<BigClass> b1;
where
MediumClass extends SmallClass
and
BigClass extends MediumClass
Seems like the injection using SmallClass should work, since what is produced will be a
MediumClass which will have all the methods needed by SmallClass.
And the injection using BigClass should fail, since what is produced will be a
MediumClass which will not have all the methods needed by BigClass.
But, according to the spec (and what seems to be enforced by the TCK) is that since
Required Type (in this case SmallClass and BigClass), must be assignable TO the Bean Type
(Medium Class), therefore the BigClass assignment is the one that works, since BigClass
is assignable TO MediumClass. But since MediumClass doesn't have all the methods
that BigClass has, then what is
produced will be insufficient for the injection.
So, is the spec misworded here? Which of these injections should be resolved, and which
one should give an error?
Bill W.
_______________________________________________
weld-dev mailing list
weld-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/weld-dev