"Type Safety" Warnings in Problems View [message #59661] |
Fri, 29 April 2005 13:32  |
Eclipse User |
|
|
|
Originally posted by: marc.esher.cablespeed.com
Greetings. In the "Problems" view, Eclipse keeps flagging HashMaps and
ArrayLists for type safety. Take the following code (BeanListHandler and
runner.query are from apache DBUtils):
1. ResultSetHandler h = new BeanListHandler(FileBean.class);
2. ArrayList <FileBean> ar_FileBeans;
3. ar_FileBeans = (ArrayList)runner.query(cn,qry_FilesOnServers,h);
Eclipse is flagging line 3 with the message "Type Safety: The Expression
of raw type ArrayList is converted to ArrayList<FileBean>. References to
generic type ArrayList<E> should be parameterized".
I'm just starting to tinker with generics.
So...how should i revise this code such that Eclipse is happy?
Thanks for input.
|
|
|
Re: "Type Safety" Warnings in Problems View [message #60404 is a reply to message #59661] |
Mon, 02 May 2005 04:23  |
Eclipse User |
|
|
|
Marc wrote:
> Greetings. In the "Problems" view, Eclipse keeps flagging HashMaps and
> ArrayLists for type safety. Take the following code (BeanListHandler and
> runner.query are from apache DBUtils):
>
> 1. ResultSetHandler h = new BeanListHandler(FileBean.class);
> 2. ArrayList <FileBean> ar_FileBeans;
>
> 3. ar_FileBeans = (ArrayList)runner.query(cn,qry_FilesOnServers,h);
>
>
> Eclipse is flagging line 3 with the message "Type Safety: The Expression
> of raw type ArrayList is converted to ArrayList<FileBean>. References to
> generic type ArrayList<E> should be parameterized".
>
> I'm just starting to tinker with generics.
>
> So...how should i revise this code such that Eclipse is happy?
You have to make the cast generic as well instead of using a raw cast:
3. ar_FileBeans =
(ArrayList<FileBean>)runner.query(cn,qry_FilesOnServers,h);
-tom
|
|
|
Powered by
FUDForum. Page generated in 0.05573 seconds