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