Can't avoid "References to generic type List<E> should be parameterized" warning here can I ?  
Author Message
S閎astien de Mapias





PostPosted: 2008-5-28 23:35:00 Top

java-programmer, Can't avoid "References to generic type List<E> should be parameterized" warning here can I ? Hi,
I'm writing some kind of gateway between 2 packages, whose a
few classes have the same name (I need to bind these classes).

So I'm retrieving the attributes of my source class1 and set my
equivalent class2 in the other pkg with these attributes when
methods names -and attributes- match.

Excerpt from my method:
1 public my.persistent.Pst mapFromProtocol(my.protocol.Pst src)
2 {
3 my.persistent.Pst target = new my.persistent.Pst();
4 for (Iterator<my.protocol.Remark> it =
src.getRemark().iterator(); it.hasNext(); )
5 target.getRemark().add(it.next());
6
7 ... //many other attributes/objects to set too
8
9 return target;
10 }

In RAD the line 5 is underlined in yellow and it says "Type safety:
The method add(Object) belongs to the raw type List. References
to generic type List<E> should be parameterized".

Is there a way to avoid this warning in my case, as I can't
instantiate
a List<Remark> lr = new ArrayList() of course... (because I have no
method setRemark() in target)

Thanks.
Regards,
Seb

 
S閎astien de Mapias





PostPosted: 2008-5-29 14:54:00 Top

java-programmer >> Can't avoid "References to generic type List<E> should be parameterized" warning here can I ? I just replaced
~ for (Iterator<my.protocol.Remark> it = src.getRemark().iterator();
it.hasNext(); )
~ target.getRemark().add(it.next());
with
~ for (my.protocol.Remark r : src.getRemark())
~ target.getRemark().add(r);
but I still have this beige serrated underline and the same warning.

Thanks for your replies.
Seb




 
voorth





PostPosted: 2008-5-29 20:11:00 Top

java-programmer >> Can't avoid "References to generic type List<E> should be parameterized" warning here can I ? On May 29, 8:54 am, S閎astien de Mapias <email***@***.com> wrote:
> I just replaced
> ~ for (Iterator<my.protocol.Remark> it = src.getRemark().iterator();
> it.hasNext(); )
> ~ target.getRemark().add(it.next());
> with
> ~ for (my.protocol.Remark r : src.getRemark())
> ~ target.getRemark().add(r);
> but I still have this beige serrated underline and the same warning.
>
> Thanks for your replies.
> Seb

Can you change the return type of getRemark() to List<Remark>?
And while you'r at it, change its name to getRemarks(). After all,
you're returning a collection of remarks.

Oh, and the for loop is probably not needed; try :
target.getRemark().addAll(src.getRemark());

Henk