[webbeans-dev] Generic classes as bean types allowed?

Pete Muir pmuir at redhat.com
Tue Aug 4 08:03:45 EDT 2009


Hi Mark,

On 3 Aug 2009, at 23:06, Dan Allen wrote:

> Yes, except it is currently broken according to this issue report: https://jira.jboss.org/jira/browse/WBRI-311
>
> If you want to see examples, check out the test cases in the TCK.
>
> And, as a parting point, this post should likely have been here: http://seamframework.org/Community/WebBeansUsersForum

We kinda use this list as a public discussion list for the spec (not  
our impl of). Perhaps the forum should be changed to the CDI User  
forum? Thoughts from anyone?

>
> -Dan
>
> On Mon, Aug 3, 2009 at 3:31 PM, Mark Struberg <struberg at yahoo.de>  
> wrote:
>
> Hi!
>
> I have the following situation:
>
> public class MyClass<T> {
> ...
> }
>
> and like to inject a specialised instance of this class:
>
> public class MyOtherBean {
>  private MyClass<Integer> myIntCls;
> }
>
> >From reading the spec (2.2.1), I was not sure if this is allowed.  
> It would make sense, since we can nail down the exact implementation  
> at the injection point. Otoh the classpath scanning part will get  
> trickier.

You need to read 5.5.3 - namely

"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, or"

here Integer is an actual type, and is assignable to the the upper  
bound of the type variable T (which is unbounded). So, as Dan said, yes.



More information about the weld-dev mailing list