users@codemodel.java.net

Re: Generics

From: Tedi Zanfolim <tedi.zanfolim_at_gmail.com>
Date: Tue, 21 Dec 2010 11:17:21 -0200

It sure helped a lot: thanks!

On Tue, Dec 21, 2010 at 3:43 AM, hussain pithawala <
hussainpithawala_at_hotmail.com> wrote:

> Hi,
>
> Simply you need to narrow down the class.
>
> This means instead of
>
> JFieldVar property = clazz.field(JMod.PRIVATE, List.class, "myList");
>
> ------------------------------------------------------------------------------
> you need to supply the narrowed class.
>
> First obtain the reference for the JClass of the intended collection
>
> JClass jClassForList = jCodeModel.ref(List.class);
>
> next narrow it down to your type.
>
> JClass jClassNarrow = jClassForList.narrow(MyObjectClass.class);
>
> then, supply it as an argument instead of the raw type.
>
> JFieldVar property = clazz.field(JMod.PRIVATE, jClassNarrow, "myList");
>
> ------------------------------------------------------------------------------
>
> Hope this is helpful.
>
> Regards
> Hussain
>
> > To: users_at_codemodel.java.net
> > From: tedi.zanfolim_at_gmail.com
> > Subject: Generics
> > Date: Tue, 21 Dec 2010 01:38:13 +0000
>
> >
> > Hi,
> >
> > I would like to generate the following code:
> >
> > private List<MyObjectClass> myList;
> >
> > But I am unable to make the list use the generic type. So far, I am
> > only able to get:
> >
> > private List myList , using the code below.
> >
> > JFieldVar property = clazz.field(JMod.PRIVATE, List.class, "myList");
> >
> > Anyone knows how to make the list parameterized?
> >
> > TIA,
> >
> > Tedi
>