Section 3.3 and use or parameterized type variables
billwigger Jan 20, 2010 3:46 PMI'm trying to understand the WebBeans, section 3.3, these two statements:
statement 1:
If the producer method return type is a parameterized type,
it must specify an actual type parameter or type variable for each type
parameter.
and
statement 2:
If a producer method return type is a type variable the container
automatically detects the problem and treats it as a definition error.
Example 1, if I code:
public class MethodTypeProduces1<T> {
@Produces @Dependent @Named("ProMethodParameterized3Str") T methodPT5() {
...
}
If fails as per statement 2:
org.apache.webbeans.exception.WebBeansConfigurationException: Producer Field/Method Bean with name : methodPT5 in bean class : com.ibm.jcdi.test.MethodTypeProduces1 return type can not be type variable
Example 2, if I code:
public class MethodTypeProduces1 {
@Produces @Dependent @Named("ProMethodParameterized3S") ArrayList<String> methodPT4() {
...
}
Then I able to inject ProMethodParameterized3S as follows:
public @Inject @Named("ProMethodParameterized3S") ArrayList<String> pt4;
which I think is the "parameterized type - actual type parameter" case mentioned in statement 1 above.
So far so good.....
Question is should the below Example 3 work or not?
Example 3
public class MethodTypeProduces1<T> {
@Produces @Dependent @Named("ProMethodParameterized3") ArrayList<T> methodPT3() {
ArrayList<T> pt = new ArrayList<T>();
pt.add(0, (T) "test string";
return pt;
}
When I inject it as follows:
public @Inject @Dependent @Named("ProMethodParameterized3") ArrayList<String> pt3;
the following error occurs:
javax.enterprise.inject.UnsatisfiedResolutionException: Api type [java.util.ArrayList] is not found with the qualifiers [@javax.inject.Named(value=ProMethodParameterized3)]
at org.apache.webbeans.container.ResolutionUtil.checkResolvedBeans(ResolutionUtil.java:93)
at org.apache.webbeans.container.InjectionResolver.getInjectionPointBean(InjectionResolver.java:232)
I was thinking this was the case in statement 1 of "parameterized type -
type variable", so it should inject without an error. But I'm not clear
on what the specification means exactly by "type variable" in this
section, and was hoping someone could clear that up.
Is example 3 a valid producer/injection?
If example 3 is not valid, what would be valid producer and inject statements for
using a "parameterized type - type variable" as describe in statement 1 above?
statement 1:
If the producer method return type is a parameterized type,
it must specify an actual type parameter or type variable for each type
parameter.
and
statement 2:
If a producer method return type is a type variable the container
automatically detects the problem and treats it as a definition error.
Example 1, if I code:
public class MethodTypeProduces1<T> {
@Produces @Dependent @Named("ProMethodParameterized3Str") T methodPT5() {
...
}
If fails as per statement 2:
org.apache.webbeans.exception.WebBeansConfigurationException: Producer Field/Method Bean with name : methodPT5 in bean class : com.ibm.jcdi.test.MethodTypeProduces1 return type can not be type variable
Example 2, if I code:
public class MethodTypeProduces1 {
@Produces @Dependent @Named("ProMethodParameterized3S") ArrayList<String> methodPT4() {
...
}
Then I able to inject ProMethodParameterized3S as follows:
public @Inject @Named("ProMethodParameterized3S") ArrayList<String> pt4;
which I think is the "parameterized type - actual type parameter" case mentioned in statement 1 above.
So far so good.....
Question is should the below Example 3 work or not?
Example 3
public class MethodTypeProduces1<T> {
@Produces @Dependent @Named("ProMethodParameterized3") ArrayList<T> methodPT3() {
ArrayList<T> pt = new ArrayList<T>();
pt.add(0, (T) "test string";
return pt;
}
When I inject it as follows:
public @Inject @Dependent @Named("ProMethodParameterized3") ArrayList<String> pt3;
the following error occurs:
javax.enterprise.inject.UnsatisfiedResolutionException: Api type [java.util.ArrayList] is not found with the qualifiers [@javax.inject.Named(value=ProMethodParameterized3)]
at org.apache.webbeans.container.ResolutionUtil.checkResolvedBeans(ResolutionUtil.java:93)
at org.apache.webbeans.container.InjectionResolver.getInjectionPointBean(InjectionResolver.java:232)
I was thinking this was the case in statement 1 of "parameterized type -
type variable", so it should inject without an error. But I'm not clear
on what the specification means exactly by "type variable" in this
section, and was hoping someone could clear that up.
Is example 3 a valid producer/injection?
If example 3 is not valid, what would be valid producer and inject statements for
using a "parameterized type - type variable" as describe in statement 1 above?