You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openwebbeans.apache.org by Arne Limburg <ar...@openknowledge.de> on 2013/07/06 09:17:48 UTC

OWB and generics

Hi,

I am currently struggling with the handling of generics in OWB, because CDI 1.1 TCK requires us to be much more clever than we are now in this area.
However I stumbled about a test in our test-suite that seems to be wrong to me, but I would like to have another opinion.
With my local implementation of the generic handling (which is much better than the one in trunk) the following tests fails:
MethodProducer1Test.testPersonProducer

Basically it tests if an ArrayList with an unbound type variable is injectable into an injection point of type ArrayList<String>:

    @Produces @Dependent @Named("ProMethodParameterized3")

    ArrayList<T> methodPT3() {...}

and

    @Inject ArrayList<String> pt3;

Reading 5.2.4 of the CDI 1.1 spec (the fourth bullet point) I would suggest that this should lead to an error since String is not assignable from Object (which is the upper bound of T).


WDYT?


Cheers,

Arne

Re: OWB and generics

Posted by Gerhard Petracek <ge...@gmail.com>.
sounds reasonable.

regards,
gerhard



2013/7/6 Arne Limburg <ar...@openknowledge.de>

> Hi,
>
> I am currently struggling with the handling of generics in OWB, because
> CDI 1.1 TCK requires us to be much more clever than we are now in this area.
> However I stumbled about a test in our test-suite that seems to be wrong
> to me, but I would like to have another opinion.
> With my local implementation of the generic handling (which is much better
> than the one in trunk) the following tests fails:
> MethodProducer1Test.testPersonProducer
>
> Basically it tests if an ArrayList with an unbound type variable is
> injectable into an injection point of type ArrayList<String>:
>
>     @Produces @Dependent @Named("ProMethodParameterized3")
>
>     ArrayList<T> methodPT3() {...}
>
> and
>
>     @Inject ArrayList<String> pt3;
>
> Reading 5.2.4 of the CDI 1.1 spec (the fourth bullet point) I would
> suggest that this should lead to an error since String is not assignable
> from Object (which is the upper bound of T).
>
>
> WDYT?
>
>
> Cheers,
>
> Arne
>

Re: OWB and generics

Posted by Romain Manni-Bucau <rm...@gmail.com>.
You can do new Foo<Bar> or new Foo<Dummy> even thats Foo<T>
Le 6 juil. 2013 12:57, "Arne Limburg" <ar...@openknowledge.de> a
écrit :

> Hi Romain,
>
>
> In plain old java the assignment does not work either:
>
> public class MyClass<T>
> {
>   ArrayList<T> myTList = ...
>   ArrayList<String> myStringList = myTList;
> }
>
> does not work...
>
> And if we have an injection point
>
> @Inject String myString;
>
> and a Producer
>
> @Produces Object myObject;
>
> then they don't match.
>
> So why should it match with generics?
>
> Cheers,
> Arne
>
> Am 06.07.13 12:50 schrieb "Romain Manni-Bucau" unter
> <rm...@gmail.com>:
>
> >So i confirm what i said, ArrayList<T> can be for String, Foo....so i
> >think
> >classes should follow it, just match what i expect since i could do it in
> >plain old java
> >Le 6 juil. 2013 10:18, "Arne Limburg" <ar...@openknowledge.de> a
> >écrit :
> >
> >> Forgot to mention that T is an unbound type variable at class level:
> >>
> >>
> >> public class MethodTypeProduces1<T>
> >>
> >> and there is no subclass of MethodTypeProduces1
> >>
> >>
> >> Am 06.07.13 10:12 schrieb "Romain Manni-Bucau" unter
> >> <rm...@gmail.com>:
> >>
> >> >Wait, not sure google ate a part of the code or not but if a <T> then T
> >> >can
> >> >be String (like ArrayList itself)
> >> >Le 6 juil. 2013 09:18, "Arne Limburg" <ar...@openknowledge.de>
> a
> >> >écrit :
> >> >
> >> >> Hi,
> >> >>
> >> >> I am currently struggling with the handling of generics in OWB,
> >>because
> >> >> CDI 1.1 TCK requires us to be much more clever than we are now in
> >>this
> >> >>area.
> >> >> However I stumbled about a test in our test-suite that seems to be
> >>wrong
> >> >> to me, but I would like to have another opinion.
> >> >> With my local implementation of the generic handling (which is much
> >> >>better
> >> >> than the one in trunk) the following tests fails:
> >> >> MethodProducer1Test.testPersonProducer
> >> >>
> >> >> Basically it tests if an ArrayList with an unbound type variable is
> >> >> injectable into an injection point of type ArrayList<String>:
> >> >>
> >> >>     @Produces @Dependent @Named("ProMethodParameterized3")
> >> >>
> >> >>     ArrayList<T> methodPT3() {...}
> >> >>
> >> >> and
> >> >>
> >> >>     @Inject ArrayList<String> pt3;
> >> >>
> >> >> Reading 5.2.4 of the CDI 1.1 spec (the fourth bullet point) I would
> >> >> suggest that this should lead to an error since String is not
> >>assignable
> >> >> from Object (which is the upper bound of T).
> >> >>
> >> >>
> >> >> WDYT?
> >> >>
> >> >>
> >> >> Cheers,
> >> >>
> >> >> Arne
> >> >>
> >>
> >>
>
>

Re: OWB and generics

Posted by Mark Struberg <st...@yahoo.de>.
Well, indeed you can if the scope is @Dependent!

A producer method with a @Dependent scope could easily investigate the InjectionPoint and create the proper Type. 
I guess that would be pretty useful - I don't know how many people would get it right though ;)

LieGrue,
strub




----- Original Message -----
From: Joseph Bergmark <be...@gmail.com>
To: dev@openwebbeans.apache.org
Cc: 
Sent: Saturday, 6 July 2013, 16:59
Subject: Re: OWB and generics

The e-mail I responded to had a non-generic example with plain old java
object which I specifically mentioned, and that is what I was referring to.

That said, I was incorrect.  Object should be in the list of bean types for
all objects.  The reason that example isn't valid is that the injection
point is specifically for a String and not for anything in String's
hierarchy.  I think the point Arne was trying to make is that you can't
assign less specific things (Object) to more specific type (String) in the
case of non-generics and was comparing that to the rules for generics.

Getting back to the point of the thread, the question is how the
introduction of generic types changes that, which I'll be the first to
admit I don't completely understand. Section 5.2.3 of CDI 1.0, and 5.2.4 of
CDI 1.1 seem to be the key.

Sincerely,

Joe

On Sat, Jul 6, 2013 at 10:47 AM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> Didnt get your answer, there is no link with Object. A produced generic
> type modelizes all possible subtypes IMO (otherwise it should be forbidden
> cause it doesnt match original java meaning then) + all beans match Object
> in the spec
> Le 6 juil. 2013 15:17, "Joseph Bergmark" <be...@apache.org> a écrit :
>
> > For some reason I believe the spec specifically says that Object should
> not
> > be in the list of types, which I believe is why your plain old java
> example
> > isn't valid.
> >
> > Joe
> >
> > On Sat, Jul 6, 2013 at 6:57 AM, Arne Limburg
> > <ar...@openknowledge.de>wrote:
> >
> > > Hi Romain,
> > >
> > >
> > > In plain old java the assignment does not work either:
> > >
> > > public class MyClass<T>
> > > {
> > >   ArrayList<T> myTList = ...
> > >   ArrayList<String> myStringList = myTList;
> > > }
> > >
> > > does not work...
> > >
> > > And if we have an injection point
> > >
> > > @Inject String myString;
> > >
> > > and a Producer
> > >
> > > @Produces Object myObject;
> > >
> > > then they don't match.
> > >
> > > So why should it match with generics?
> > >
> > > Cheers,
> > > Arne
> > >
> > > Am 06.07.13 12:50 schrieb "Romain Manni-Bucau" unter
> > > <rm...@gmail.com>:
> > >
> > > >So i confirm what i said, ArrayList<T> can be for String, Foo....so i
> > > >think
> > > >classes should follow it, just match what i expect since i could do it
> > in
> > > >plain old java
> > > >Le 6 juil. 2013 10:18, "Arne Limburg" <ar...@openknowledge.de>
> a
> > > >écrit :
> > > >
> > > >> Forgot to mention that T is an unbound type variable at class level:
> > > >>
> > > >>
> > > >> public class MethodTypeProduces1<T>
> > > >>
> > > >> and there is no subclass of MethodTypeProduces1
> > > >>
> > > >>
> > > >> Am 06.07.13 10:12 schrieb "Romain Manni-Bucau" unter
> > > >> <rm...@gmail.com>:
> > > >>
> > > >> >Wait, not sure google ate a part of the code or not but if a <T>
> > then T
> > > >> >can
> > > >> >be String (like ArrayList itself)
> > > >> >Le 6 juil. 2013 09:18, "Arne Limburg" <
> arne.limburg@openknowledge.de
> > >
> > > a
> > > >> >écrit :
> > > >> >
> > > >> >> Hi,
> > > >> >>
> > > >> >> I am currently struggling with the handling of generics in OWB,
> > > >>because
> > > >> >> CDI 1.1 TCK requires us to be much more clever than we are now in
> > > >>this
> > > >> >>area.
> > > >> >> However I stumbled about a test in our test-suite that seems to
> be
> > > >>wrong
> > > >> >> to me, but I would like to have another opinion.
> > > >> >> With my local implementation of the generic handling (which is
> much
> > > >> >>better
> > > >> >> than the one in trunk) the following tests fails:
> > > >> >> MethodProducer1Test.testPersonProducer
> > > >> >>
> > > >> >> Basically it tests if an ArrayList with an unbound type variable
> is
> > > >> >> injectable into an injection point of type ArrayList<String>:
> > > >> >>
> > > >> >>     @Produces @Dependent @Named("ProMethodParameterized3")
> > > >> >>
> > > >> >>     ArrayList<T> methodPT3() {...}
> > > >> >>
> > > >> >> and
> > > >> >>
> > > >> >>     @Inject ArrayList<String> pt3;
> > > >> >>
> > > >> >> Reading 5.2.4 of the CDI 1.1 spec (the fourth bullet point) I
> would
> > > >> >> suggest that this should lead to an error since String is not
> > > >>assignable
> > > >> >> from Object (which is the upper bound of T).
> > > >> >>
> > > >> >>
> > > >> >> WDYT?
> > > >> >>
> > > >> >>
> > > >> >> Cheers,
> > > >> >>
> > > >> >> Arne
> > > >> >>
> > > >>
> > > >>
> > >
> > >
> >
> 

Re: OWB and generics

Posted by Joseph Bergmark <be...@gmail.com>.
The e-mail I responded to had a non-generic example with plain old java
object which I specifically mentioned, and that is what I was referring to.

That said, I was incorrect.  Object should be in the list of bean types for
all objects.  The reason that example isn't valid is that the injection
point is specifically for a String and not for anything in String's
hierarchy.  I think the point Arne was trying to make is that you can't
assign less specific things (Object) to more specific type (String) in the
case of non-generics and was comparing that to the rules for generics.

Getting back to the point of the thread, the question is how the
introduction of generic types changes that, which I'll be the first to
admit I don't completely understand. Section 5.2.3 of CDI 1.0, and 5.2.4 of
CDI 1.1 seem to be the key.

Sincerely,

Joe

On Sat, Jul 6, 2013 at 10:47 AM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> Didnt get your answer, there is no link with Object. A produced generic
> type modelizes all possible subtypes IMO (otherwise it should be forbidden
> cause it doesnt match original java meaning then) + all beans match Object
> in the spec
> Le 6 juil. 2013 15:17, "Joseph Bergmark" <be...@apache.org> a écrit :
>
> > For some reason I believe the spec specifically says that Object should
> not
> > be in the list of types, which I believe is why your plain old java
> example
> > isn't valid.
> >
> > Joe
> >
> > On Sat, Jul 6, 2013 at 6:57 AM, Arne Limburg
> > <ar...@openknowledge.de>wrote:
> >
> > > Hi Romain,
> > >
> > >
> > > In plain old java the assignment does not work either:
> > >
> > > public class MyClass<T>
> > > {
> > >   ArrayList<T> myTList = ...
> > >   ArrayList<String> myStringList = myTList;
> > > }
> > >
> > > does not work...
> > >
> > > And if we have an injection point
> > >
> > > @Inject String myString;
> > >
> > > and a Producer
> > >
> > > @Produces Object myObject;
> > >
> > > then they don't match.
> > >
> > > So why should it match with generics?
> > >
> > > Cheers,
> > > Arne
> > >
> > > Am 06.07.13 12:50 schrieb "Romain Manni-Bucau" unter
> > > <rm...@gmail.com>:
> > >
> > > >So i confirm what i said, ArrayList<T> can be for String, Foo....so i
> > > >think
> > > >classes should follow it, just match what i expect since i could do it
> > in
> > > >plain old java
> > > >Le 6 juil. 2013 10:18, "Arne Limburg" <ar...@openknowledge.de>
> a
> > > >écrit :
> > > >
> > > >> Forgot to mention that T is an unbound type variable at class level:
> > > >>
> > > >>
> > > >> public class MethodTypeProduces1<T>
> > > >>
> > > >> and there is no subclass of MethodTypeProduces1
> > > >>
> > > >>
> > > >> Am 06.07.13 10:12 schrieb "Romain Manni-Bucau" unter
> > > >> <rm...@gmail.com>:
> > > >>
> > > >> >Wait, not sure google ate a part of the code or not but if a <T>
> > then T
> > > >> >can
> > > >> >be String (like ArrayList itself)
> > > >> >Le 6 juil. 2013 09:18, "Arne Limburg" <
> arne.limburg@openknowledge.de
> > >
> > > a
> > > >> >écrit :
> > > >> >
> > > >> >> Hi,
> > > >> >>
> > > >> >> I am currently struggling with the handling of generics in OWB,
> > > >>because
> > > >> >> CDI 1.1 TCK requires us to be much more clever than we are now in
> > > >>this
> > > >> >>area.
> > > >> >> However I stumbled about a test in our test-suite that seems to
> be
> > > >>wrong
> > > >> >> to me, but I would like to have another opinion.
> > > >> >> With my local implementation of the generic handling (which is
> much
> > > >> >>better
> > > >> >> than the one in trunk) the following tests fails:
> > > >> >> MethodProducer1Test.testPersonProducer
> > > >> >>
> > > >> >> Basically it tests if an ArrayList with an unbound type variable
> is
> > > >> >> injectable into an injection point of type ArrayList<String>:
> > > >> >>
> > > >> >>     @Produces @Dependent @Named("ProMethodParameterized3")
> > > >> >>
> > > >> >>     ArrayList<T> methodPT3() {...}
> > > >> >>
> > > >> >> and
> > > >> >>
> > > >> >>     @Inject ArrayList<String> pt3;
> > > >> >>
> > > >> >> Reading 5.2.4 of the CDI 1.1 spec (the fourth bullet point) I
> would
> > > >> >> suggest that this should lead to an error since String is not
> > > >>assignable
> > > >> >> from Object (which is the upper bound of T).
> > > >> >>
> > > >> >>
> > > >> >> WDYT?
> > > >> >>
> > > >> >>
> > > >> >> Cheers,
> > > >> >>
> > > >> >> Arne
> > > >> >>
> > > >>
> > > >>
> > >
> > >
> >
>

Re: OWB and generics

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Didnt get your answer, there is no link with Object. A produced generic
type modelizes all possible subtypes IMO (otherwise it should be forbidden
cause it doesnt match original java meaning then) + all beans match Object
in the spec
Le 6 juil. 2013 15:17, "Joseph Bergmark" <be...@apache.org> a écrit :

> For some reason I believe the spec specifically says that Object should not
> be in the list of types, which I believe is why your plain old java example
> isn't valid.
>
> Joe
>
> On Sat, Jul 6, 2013 at 6:57 AM, Arne Limburg
> <ar...@openknowledge.de>wrote:
>
> > Hi Romain,
> >
> >
> > In plain old java the assignment does not work either:
> >
> > public class MyClass<T>
> > {
> >   ArrayList<T> myTList = ...
> >   ArrayList<String> myStringList = myTList;
> > }
> >
> > does not work...
> >
> > And if we have an injection point
> >
> > @Inject String myString;
> >
> > and a Producer
> >
> > @Produces Object myObject;
> >
> > then they don't match.
> >
> > So why should it match with generics?
> >
> > Cheers,
> > Arne
> >
> > Am 06.07.13 12:50 schrieb "Romain Manni-Bucau" unter
> > <rm...@gmail.com>:
> >
> > >So i confirm what i said, ArrayList<T> can be for String, Foo....so i
> > >think
> > >classes should follow it, just match what i expect since i could do it
> in
> > >plain old java
> > >Le 6 juil. 2013 10:18, "Arne Limburg" <ar...@openknowledge.de> a
> > >écrit :
> > >
> > >> Forgot to mention that T is an unbound type variable at class level:
> > >>
> > >>
> > >> public class MethodTypeProduces1<T>
> > >>
> > >> and there is no subclass of MethodTypeProduces1
> > >>
> > >>
> > >> Am 06.07.13 10:12 schrieb "Romain Manni-Bucau" unter
> > >> <rm...@gmail.com>:
> > >>
> > >> >Wait, not sure google ate a part of the code or not but if a <T>
> then T
> > >> >can
> > >> >be String (like ArrayList itself)
> > >> >Le 6 juil. 2013 09:18, "Arne Limburg" <arne.limburg@openknowledge.de
> >
> > a
> > >> >écrit :
> > >> >
> > >> >> Hi,
> > >> >>
> > >> >> I am currently struggling with the handling of generics in OWB,
> > >>because
> > >> >> CDI 1.1 TCK requires us to be much more clever than we are now in
> > >>this
> > >> >>area.
> > >> >> However I stumbled about a test in our test-suite that seems to be
> > >>wrong
> > >> >> to me, but I would like to have another opinion.
> > >> >> With my local implementation of the generic handling (which is much
> > >> >>better
> > >> >> than the one in trunk) the following tests fails:
> > >> >> MethodProducer1Test.testPersonProducer
> > >> >>
> > >> >> Basically it tests if an ArrayList with an unbound type variable is
> > >> >> injectable into an injection point of type ArrayList<String>:
> > >> >>
> > >> >>     @Produces @Dependent @Named("ProMethodParameterized3")
> > >> >>
> > >> >>     ArrayList<T> methodPT3() {...}
> > >> >>
> > >> >> and
> > >> >>
> > >> >>     @Inject ArrayList<String> pt3;
> > >> >>
> > >> >> Reading 5.2.4 of the CDI 1.1 spec (the fourth bullet point) I would
> > >> >> suggest that this should lead to an error since String is not
> > >>assignable
> > >> >> from Object (which is the upper bound of T).
> > >> >>
> > >> >>
> > >> >> WDYT?
> > >> >>
> > >> >>
> > >> >> Cheers,
> > >> >>
> > >> >> Arne
> > >> >>
> > >>
> > >>
> >
> >
>

Re: OWB and generics

Posted by Joseph Bergmark <be...@apache.org>.
For some reason I believe the spec specifically says that Object should not
be in the list of types, which I believe is why your plain old java example
isn't valid.

Joe

On Sat, Jul 6, 2013 at 6:57 AM, Arne Limburg
<ar...@openknowledge.de>wrote:

> Hi Romain,
>
>
> In plain old java the assignment does not work either:
>
> public class MyClass<T>
> {
>   ArrayList<T> myTList = ...
>   ArrayList<String> myStringList = myTList;
> }
>
> does not work...
>
> And if we have an injection point
>
> @Inject String myString;
>
> and a Producer
>
> @Produces Object myObject;
>
> then they don't match.
>
> So why should it match with generics?
>
> Cheers,
> Arne
>
> Am 06.07.13 12:50 schrieb "Romain Manni-Bucau" unter
> <rm...@gmail.com>:
>
> >So i confirm what i said, ArrayList<T> can be for String, Foo....so i
> >think
> >classes should follow it, just match what i expect since i could do it in
> >plain old java
> >Le 6 juil. 2013 10:18, "Arne Limburg" <ar...@openknowledge.de> a
> >écrit :
> >
> >> Forgot to mention that T is an unbound type variable at class level:
> >>
> >>
> >> public class MethodTypeProduces1<T>
> >>
> >> and there is no subclass of MethodTypeProduces1
> >>
> >>
> >> Am 06.07.13 10:12 schrieb "Romain Manni-Bucau" unter
> >> <rm...@gmail.com>:
> >>
> >> >Wait, not sure google ate a part of the code or not but if a <T> then T
> >> >can
> >> >be String (like ArrayList itself)
> >> >Le 6 juil. 2013 09:18, "Arne Limburg" <ar...@openknowledge.de>
> a
> >> >écrit :
> >> >
> >> >> Hi,
> >> >>
> >> >> I am currently struggling with the handling of generics in OWB,
> >>because
> >> >> CDI 1.1 TCK requires us to be much more clever than we are now in
> >>this
> >> >>area.
> >> >> However I stumbled about a test in our test-suite that seems to be
> >>wrong
> >> >> to me, but I would like to have another opinion.
> >> >> With my local implementation of the generic handling (which is much
> >> >>better
> >> >> than the one in trunk) the following tests fails:
> >> >> MethodProducer1Test.testPersonProducer
> >> >>
> >> >> Basically it tests if an ArrayList with an unbound type variable is
> >> >> injectable into an injection point of type ArrayList<String>:
> >> >>
> >> >>     @Produces @Dependent @Named("ProMethodParameterized3")
> >> >>
> >> >>     ArrayList<T> methodPT3() {...}
> >> >>
> >> >> and
> >> >>
> >> >>     @Inject ArrayList<String> pt3;
> >> >>
> >> >> Reading 5.2.4 of the CDI 1.1 spec (the fourth bullet point) I would
> >> >> suggest that this should lead to an error since String is not
> >>assignable
> >> >> from Object (which is the upper bound of T).
> >> >>
> >> >>
> >> >> WDYT?
> >> >>
> >> >>
> >> >> Cheers,
> >> >>
> >> >> Arne
> >> >>
> >>
> >>
>
>

Re: OWB and generics

Posted by Arne Limburg <ar...@openknowledge.de>.
Hi Romain,


In plain old java the assignment does not work either:

public class MyClass<T>
{
  ArrayList<T> myTList = ...
  ArrayList<String> myStringList = myTList;
}

does not work...

And if we have an injection point

@Inject String myString;

and a Producer

@Produces Object myObject;

then they don't match.

So why should it match with generics?

Cheers,
Arne

Am 06.07.13 12:50 schrieb "Romain Manni-Bucau" unter
<rm...@gmail.com>:

>So i confirm what i said, ArrayList<T> can be for String, Foo....so i
>think
>classes should follow it, just match what i expect since i could do it in
>plain old java
>Le 6 juil. 2013 10:18, "Arne Limburg" <ar...@openknowledge.de> a
>écrit :
>
>> Forgot to mention that T is an unbound type variable at class level:
>>
>>
>> public class MethodTypeProduces1<T>
>>
>> and there is no subclass of MethodTypeProduces1
>>
>>
>> Am 06.07.13 10:12 schrieb "Romain Manni-Bucau" unter
>> <rm...@gmail.com>:
>>
>> >Wait, not sure google ate a part of the code or not but if a <T> then T
>> >can
>> >be String (like ArrayList itself)
>> >Le 6 juil. 2013 09:18, "Arne Limburg" <ar...@openknowledge.de> a
>> >écrit :
>> >
>> >> Hi,
>> >>
>> >> I am currently struggling with the handling of generics in OWB,
>>because
>> >> CDI 1.1 TCK requires us to be much more clever than we are now in
>>this
>> >>area.
>> >> However I stumbled about a test in our test-suite that seems to be
>>wrong
>> >> to me, but I would like to have another opinion.
>> >> With my local implementation of the generic handling (which is much
>> >>better
>> >> than the one in trunk) the following tests fails:
>> >> MethodProducer1Test.testPersonProducer
>> >>
>> >> Basically it tests if an ArrayList with an unbound type variable is
>> >> injectable into an injection point of type ArrayList<String>:
>> >>
>> >>     @Produces @Dependent @Named("ProMethodParameterized3")
>> >>
>> >>     ArrayList<T> methodPT3() {...}
>> >>
>> >> and
>> >>
>> >>     @Inject ArrayList<String> pt3;
>> >>
>> >> Reading 5.2.4 of the CDI 1.1 spec (the fourth bullet point) I would
>> >> suggest that this should lead to an error since String is not
>>assignable
>> >> from Object (which is the upper bound of T).
>> >>
>> >>
>> >> WDYT?
>> >>
>> >>
>> >> Cheers,
>> >>
>> >> Arne
>> >>
>>
>>


Re: OWB and generics

Posted by Romain Manni-Bucau <rm...@gmail.com>.
So i confirm what i said, ArrayList<T> can be for String, Foo....so i think
classes should follow it, just match what i expect since i could do it in
plain old java
Le 6 juil. 2013 10:18, "Arne Limburg" <ar...@openknowledge.de> a
écrit :

> Forgot to mention that T is an unbound type variable at class level:
>
>
> public class MethodTypeProduces1<T>
>
> and there is no subclass of MethodTypeProduces1
>
>
> Am 06.07.13 10:12 schrieb "Romain Manni-Bucau" unter
> <rm...@gmail.com>:
>
> >Wait, not sure google ate a part of the code or not but if a <T> then T
> >can
> >be String (like ArrayList itself)
> >Le 6 juil. 2013 09:18, "Arne Limburg" <ar...@openknowledge.de> a
> >écrit :
> >
> >> Hi,
> >>
> >> I am currently struggling with the handling of generics in OWB, because
> >> CDI 1.1 TCK requires us to be much more clever than we are now in this
> >>area.
> >> However I stumbled about a test in our test-suite that seems to be wrong
> >> to me, but I would like to have another opinion.
> >> With my local implementation of the generic handling (which is much
> >>better
> >> than the one in trunk) the following tests fails:
> >> MethodProducer1Test.testPersonProducer
> >>
> >> Basically it tests if an ArrayList with an unbound type variable is
> >> injectable into an injection point of type ArrayList<String>:
> >>
> >>     @Produces @Dependent @Named("ProMethodParameterized3")
> >>
> >>     ArrayList<T> methodPT3() {...}
> >>
> >> and
> >>
> >>     @Inject ArrayList<String> pt3;
> >>
> >> Reading 5.2.4 of the CDI 1.1 spec (the fourth bullet point) I would
> >> suggest that this should lead to an error since String is not assignable
> >> from Object (which is the upper bound of T).
> >>
> >>
> >> WDYT?
> >>
> >>
> >> Cheers,
> >>
> >> Arne
> >>
>
>

Re: OWB and generics

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

It looks ambiguous to me
Le 6 juil. 2013 20:16, "Arne Limburg" <ar...@openknowledge.de> a
écrit :

> Anyway,
> I took a look into the CDI 1.1 TCK, which has a quite interesting
> deployment scenario with generics:
>
> public class Baz<T> {
> }
>
> public class Qux extends Baz<String> {
> }
>
>
>
> @Vetoed
> public class Bar<T1, T2> {
>   @Inject
>   private Baz<T1> baz;
>   @Inject
>   private Baz<List<T2>> t2BazList;
> }
>
>
>
> @RequestScoped
> public class Foo extends Bar<String, Qux> {
> }
>
>
> public class Producer {
>   @Produces
>   @Amazing
>   public String produceString() {
>     return "ok";
>   }
>
>   @Produces
>   public String[] produceStringArray() {
>     return new String[0];
>   }
>
>   @Produces
>   public Baz<Baz<Qux>> produceBazBazQux() {
>     return new Baz();
>   }
> }
>
> The class Bar has some more injection points, but that does not matter.
> Due to the TCK this deployment should work, but I don't know how.
> Question (it is basically the question we are discussing here): Is Baz a
> Bean (I suppose so) and may it be injected into the second injection point
> of Bean Foo in class Bar?
> - If yes, it also should be injected into the first injection point,
> right? This would lead to an AmbiguousResolutionException since Qux could
> also be injected into the first injection point.
> - If no, the deployment should fail with a UnsatisfiedResolutionException
> since there is no Bean that can be injected into that injection point.
>
> WDYT?
>
> If noone can shed light into this, I will cross-post this mail to the
> cdi-dev list.
>
> Cheers,
> Arne
>
>
>
> Am 06.07.13 19:00 schrieb "Mark Struberg" unter <st...@yahoo.de>:
>
> >I thought about this a bit now. This is a bit of a mixed bag.
> >
> >Another pov is:
> >
> >ArrayList<T> which gets erased to ArrayList<Object> should be treated as
> >ArrayList.
> >
> >Now for the question: does a Producer for ArrayList also get used for an
> >InjectionPoint of ArrayList<String>?
> >In CDI 1.0 only the other way around was specified. We had this
> >discussion with the Weld guys and also had this code in some CDI
> >Extensions.
> >
> >Not an easy topic indeed.
> >
> >LieGrue,
> >strub
> >
> >
> >
> >
> >----- Original Message -----
> >From: Arne Limburg <ar...@openknowledge.de>
> >To: "dev@openwebbeans.apache.org" <de...@openwebbeans.apache.org>
> >Cc:
> >Sent: Saturday, 6 July 2013, 10:18
> >Subject: Re: OWB and generics
> >
> >Forgot to mention that T is an unbound type variable at class level:
> >
> >
> >public class MethodTypeProduces1<T>
> >
> >and there is no subclass of MethodTypeProduces1
> >
> >
> >Am 06.07.13 10:12 schrieb "Romain Manni-Bucau" unter
> ><rm...@gmail.com>:
> >
> >>Wait, not sure google ate a part of the code or not but if a <T> then T
> >>can
> >>be String (like ArrayList itself)
> >>Le 6 juil. 2013 09:18, "Arne Limburg" <ar...@openknowledge.de> a
> >>écrit :
> >>
> >>> Hi,
> >>>
> >>> I am currently struggling with the handling of generics in OWB, because
> >>> CDI 1.1 TCK requires us to be much more clever than we are now in this
> >>>area.
> >>> However I stumbled about a test in our test-suite that seems to be
> >>>wrong
> >>> to me, but I would like to have another opinion.
> >>> With my local implementation of the generic handling (which is much
> >>>better
> >>> than the one in trunk) the following tests fails:
> >>> MethodProducer1Test.testPersonProducer
> >>>
> >>> Basically it tests if an ArrayList with an unbound type variable is
> >>> injectable into an injection point of type ArrayList<String>:
> >>>
> >>>     @Produces @Dependent @Named("ProMethodParameterized3")
> >>>
> >>>     ArrayList<T> methodPT3() {...}
> >>>
> >>> and
> >>>
> >>>     @Inject ArrayList<String> pt3;
> >>>
> >>> Reading 5.2.4 of the CDI 1.1 spec (the fourth bullet point) I would
> >>> suggest that this should lead to an error since String is not
> >>>assignable
> >>> from Object (which is the upper bound of T).
> >>>
> >>>
> >>> WDYT?
> >>>
> >>>
> >>> Cheers,
> >>>
> >>> Arne
> >>>
> >
>
>

Re: OWB and generics

Posted by Arne Limburg <ar...@openknowledge.de>.
Anyway,
I took a look into the CDI 1.1 TCK, which has a quite interesting
deployment scenario with generics:

public class Baz<T> {
}

public class Qux extends Baz<String> {
}



@Vetoed
public class Bar<T1, T2> {
  @Inject
  private Baz<T1> baz;
  @Inject
  private Baz<List<T2>> t2BazList;
}



@RequestScoped
public class Foo extends Bar<String, Qux> {
}


public class Producer {
  @Produces
  @Amazing
  public String produceString() {
    return "ok";
  }

  @Produces
  public String[] produceStringArray() {
    return new String[0];
  }

  @Produces
  public Baz<Baz<Qux>> produceBazBazQux() {
    return new Baz();
  }
}

The class Bar has some more injection points, but that does not matter.
Due to the TCK this deployment should work, but I don't know how.
Question (it is basically the question we are discussing here): Is Baz a
Bean (I suppose so) and may it be injected into the second injection point
of Bean Foo in class Bar?
- If yes, it also should be injected into the first injection point,
right? This would lead to an AmbiguousResolutionException since Qux could
also be injected into the first injection point.
- If no, the deployment should fail with a UnsatisfiedResolutionException
since there is no Bean that can be injected into that injection point.

WDYT?

If noone can shed light into this, I will cross-post this mail to the
cdi-dev list.

Cheers,
Arne



Am 06.07.13 19:00 schrieb "Mark Struberg" unter <st...@yahoo.de>:

>I thought about this a bit now. This is a bit of a mixed bag.
>
>Another pov is:
>
>ArrayList<T> which gets erased to ArrayList<Object> should be treated as
>ArrayList.
>
>Now for the question: does a Producer for ArrayList also get used for an
>InjectionPoint of ArrayList<String>?
>In CDI 1.0 only the other way around was specified. We had this
>discussion with the Weld guys and also had this code in some CDI
>Extensions.
>
>Not an easy topic indeed.
>
>LieGrue,
>strub
>
>
>
>
>----- Original Message -----
>From: Arne Limburg <ar...@openknowledge.de>
>To: "dev@openwebbeans.apache.org" <de...@openwebbeans.apache.org>
>Cc: 
>Sent: Saturday, 6 July 2013, 10:18
>Subject: Re: OWB and generics
>
>Forgot to mention that T is an unbound type variable at class level:
>
>
>public class MethodTypeProduces1<T>
>
>and there is no subclass of MethodTypeProduces1
>
>
>Am 06.07.13 10:12 schrieb "Romain Manni-Bucau" unter
><rm...@gmail.com>:
>
>>Wait, not sure google ate a part of the code or not but if a <T> then T
>>can
>>be String (like ArrayList itself)
>>Le 6 juil. 2013 09:18, "Arne Limburg" <ar...@openknowledge.de> a
>>écrit :
>>
>>> Hi,
>>>
>>> I am currently struggling with the handling of generics in OWB, because
>>> CDI 1.1 TCK requires us to be much more clever than we are now in this
>>>area.
>>> However I stumbled about a test in our test-suite that seems to be
>>>wrong
>>> to me, but I would like to have another opinion.
>>> With my local implementation of the generic handling (which is much
>>>better
>>> than the one in trunk) the following tests fails:
>>> MethodProducer1Test.testPersonProducer
>>>
>>> Basically it tests if an ArrayList with an unbound type variable is
>>> injectable into an injection point of type ArrayList<String>:
>>>
>>>     @Produces @Dependent @Named("ProMethodParameterized3")
>>>
>>>     ArrayList<T> methodPT3() {...}
>>>
>>> and
>>>
>>>     @Inject ArrayList<String> pt3;
>>>
>>> Reading 5.2.4 of the CDI 1.1 spec (the fourth bullet point) I would
>>> suggest that this should lead to an error since String is not
>>>assignable
>>> from Object (which is the upper bound of T).
>>>
>>>
>>> WDYT?
>>>
>>>
>>> Cheers,
>>>
>>> Arne
>>>
>


Re: OWB and generics

Posted by Arne Limburg <ar...@openknowledge.de>.
OK,
I read from Martin Koubas answer on the CDI dev list, that our
ArrayList<T> producer result is not injectable into an injection point of
type ArrayList<String> and will implement it that way.

Cheers,
Arne


Am 06.07.13 19:00 schrieb "Mark Struberg" unter <st...@yahoo.de>:

>I thought about this a bit now. This is a bit of a mixed bag.
>
>Another pov is:
>
>ArrayList<T> which gets erased to ArrayList<Object> should be treated as
>ArrayList.
>
>Now for the question: does a Producer for ArrayList also get used for an
>InjectionPoint of ArrayList<String>?
>In CDI 1.0 only the other way around was specified. We had this
>discussion with the Weld guys and also had this code in some CDI
>Extensions.
>
>Not an easy topic indeed.
>
>LieGrue,
>strub
>
>
>
>
>----- Original Message -----
>From: Arne Limburg <ar...@openknowledge.de>
>To: "dev@openwebbeans.apache.org" <de...@openwebbeans.apache.org>
>Cc: 
>Sent: Saturday, 6 July 2013, 10:18
>Subject: Re: OWB and generics
>
>Forgot to mention that T is an unbound type variable at class level:
>
>
>public class MethodTypeProduces1<T>
>
>and there is no subclass of MethodTypeProduces1
>
>
>Am 06.07.13 10:12 schrieb "Romain Manni-Bucau" unter
><rm...@gmail.com>:
>
>>Wait, not sure google ate a part of the code or not but if a <T> then T
>>can
>>be String (like ArrayList itself)
>>Le 6 juil. 2013 09:18, "Arne Limburg" <ar...@openknowledge.de> a
>>écrit :
>>
>>> Hi,
>>>
>>> I am currently struggling with the handling of generics in OWB, because
>>> CDI 1.1 TCK requires us to be much more clever than we are now in this
>>>area.
>>> However I stumbled about a test in our test-suite that seems to be
>>>wrong
>>> to me, but I would like to have another opinion.
>>> With my local implementation of the generic handling (which is much
>>>better
>>> than the one in trunk) the following tests fails:
>>> MethodProducer1Test.testPersonProducer
>>>
>>> Basically it tests if an ArrayList with an unbound type variable is
>>> injectable into an injection point of type ArrayList<String>:
>>>
>>>     @Produces @Dependent @Named("ProMethodParameterized3")
>>>
>>>     ArrayList<T> methodPT3() {...}
>>>
>>> and
>>>
>>>     @Inject ArrayList<String> pt3;
>>>
>>> Reading 5.2.4 of the CDI 1.1 spec (the fourth bullet point) I would
>>> suggest that this should lead to an error since String is not
>>>assignable
>>> from Object (which is the upper bound of T).
>>>
>>>
>>> WDYT?
>>>
>>>
>>> Cheers,
>>>
>>> Arne
>>>
>


Re: OWB and generics

Posted by Mark Struberg <st...@yahoo.de>.
I thought about this a bit now. This is a bit of a mixed bag.

Another pov is:

ArrayList<T> which gets erased to ArrayList<Object> should be treated as ArrayList.

Now for the question: does a Producer for ArrayList also get used for an InjectionPoint of ArrayList<String>?
In CDI 1.0 only the other way around was specified. We had this discussion with the Weld guys and also had this code in some CDI Extensions.

Not an easy topic indeed.

LieGrue,
strub




----- Original Message -----
From: Arne Limburg <ar...@openknowledge.de>
To: "dev@openwebbeans.apache.org" <de...@openwebbeans.apache.org>
Cc: 
Sent: Saturday, 6 July 2013, 10:18
Subject: Re: OWB and generics

Forgot to mention that T is an unbound type variable at class level:


public class MethodTypeProduces1<T>

and there is no subclass of MethodTypeProduces1


Am 06.07.13 10:12 schrieb "Romain Manni-Bucau" unter
<rm...@gmail.com>:

>Wait, not sure google ate a part of the code or not but if a <T> then T
>can
>be String (like ArrayList itself)
>Le 6 juil. 2013 09:18, "Arne Limburg" <ar...@openknowledge.de> a
>écrit :
>
>> Hi,
>>
>> I am currently struggling with the handling of generics in OWB, because
>> CDI 1.1 TCK requires us to be much more clever than we are now in this
>>area.
>> However I stumbled about a test in our test-suite that seems to be wrong
>> to me, but I would like to have another opinion.
>> With my local implementation of the generic handling (which is much
>>better
>> than the one in trunk) the following tests fails:
>> MethodProducer1Test.testPersonProducer
>>
>> Basically it tests if an ArrayList with an unbound type variable is
>> injectable into an injection point of type ArrayList<String>:
>>
>>     @Produces @Dependent @Named("ProMethodParameterized3")
>>
>>     ArrayList<T> methodPT3() {...}
>>
>> and
>>
>>     @Inject ArrayList<String> pt3;
>>
>> Reading 5.2.4 of the CDI 1.1 spec (the fourth bullet point) I would
>> suggest that this should lead to an error since String is not assignable
>> from Object (which is the upper bound of T).
>>
>>
>> WDYT?
>>
>>
>> Cheers,
>>
>> Arne
>>


Re: OWB and generics

Posted by Arne Limburg <ar...@openknowledge.de>.
Forgot to mention that T is an unbound type variable at class level:


public class MethodTypeProduces1<T>

and there is no subclass of MethodTypeProduces1


Am 06.07.13 10:12 schrieb "Romain Manni-Bucau" unter
<rm...@gmail.com>:

>Wait, not sure google ate a part of the code or not but if a <T> then T
>can
>be String (like ArrayList itself)
>Le 6 juil. 2013 09:18, "Arne Limburg" <ar...@openknowledge.de> a
>écrit :
>
>> Hi,
>>
>> I am currently struggling with the handling of generics in OWB, because
>> CDI 1.1 TCK requires us to be much more clever than we are now in this
>>area.
>> However I stumbled about a test in our test-suite that seems to be wrong
>> to me, but I would like to have another opinion.
>> With my local implementation of the generic handling (which is much
>>better
>> than the one in trunk) the following tests fails:
>> MethodProducer1Test.testPersonProducer
>>
>> Basically it tests if an ArrayList with an unbound type variable is
>> injectable into an injection point of type ArrayList<String>:
>>
>>     @Produces @Dependent @Named("ProMethodParameterized3")
>>
>>     ArrayList<T> methodPT3() {...}
>>
>> and
>>
>>     @Inject ArrayList<String> pt3;
>>
>> Reading 5.2.4 of the CDI 1.1 spec (the fourth bullet point) I would
>> suggest that this should lead to an error since String is not assignable
>> from Object (which is the upper bound of T).
>>
>>
>> WDYT?
>>
>>
>> Cheers,
>>
>> Arne
>>


Re: OWB and generics

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Wait, not sure google ate a part of the code or not but if a <T> then T can
be String (like ArrayList itself)
Le 6 juil. 2013 09:18, "Arne Limburg" <ar...@openknowledge.de> a
écrit :

> Hi,
>
> I am currently struggling with the handling of generics in OWB, because
> CDI 1.1 TCK requires us to be much more clever than we are now in this area.
> However I stumbled about a test in our test-suite that seems to be wrong
> to me, but I would like to have another opinion.
> With my local implementation of the generic handling (which is much better
> than the one in trunk) the following tests fails:
> MethodProducer1Test.testPersonProducer
>
> Basically it tests if an ArrayList with an unbound type variable is
> injectable into an injection point of type ArrayList<String>:
>
>     @Produces @Dependent @Named("ProMethodParameterized3")
>
>     ArrayList<T> methodPT3() {...}
>
> and
>
>     @Inject ArrayList<String> pt3;
>
> Reading 5.2.4 of the CDI 1.1 spec (the fourth bullet point) I would
> suggest that this should lead to an error since String is not assignable
> from Object (which is the upper bound of T).
>
>
> WDYT?
>
>
> Cheers,
>
> Arne
>