another type safety warning with generics [message #115000] |
Sat, 05 November 2005 21:18  |
Eclipse User |
|
|
|
Originally posted by: marc_e.ye.olde.spam.buster.cablespeed.com
i imagine i'm doing something wrong with generics, as eclipse is filling up
my problems view with messages such as this:
"The cast from Object to ArrayList<RequestBean> is actually checking against
the erased type "
here's the code in question:
ArrayList<RequestBean> ar_RequestBeans = new ArrayList<RequestBean>();
ar_RequestBeans = (ArrayList<RequestBean>)runner.query(cn,sql,h);
What's wrong here?
thanks a lot.
Marc
|
|
|
|
Re: another type safety warning with generics [message #115355 is a reply to message #115120] |
Mon, 07 November 2005 16:14  |
Eclipse User |
|
|
|
Originally posted by: marc_e.ye.olde.spam.buster.cablespeed.com
Yes, I'm aware this isn't an eclipse problem. What I'm wondering is: is this
bad code?
I've read a good deal on generics and don't recall ever having to do
anything more than this. Do I?
Thanks for responding.
"Adam Kiezun" <akiezun@remove.mit.edu> wrote in message
news:dkmkdj$l6t$1@news.eclipse.org...
> Marc E wrote:
>> i imagine i'm doing something wrong with generics, as eclipse is filling
>> up my problems view with messages such as this:
>>
>> "The cast from Object to ArrayList<RequestBean> is actually checking
>> against the erased type "
>>
>> here's the code in question:
>>
>> ArrayList<RequestBean> ar_RequestBeans = new ArrayList<RequestBean>();
>> ar_RequestBeans = (ArrayList<RequestBean>)runner.query(cn,sql,h);
>>
>> What's wrong here?
>
> Generics are implemented by erasure,
> whatever is between angle brackets at compile time is gone at runtime.
> So the cast is actually just a cast to ArrayList.
> And thus the compiler rightly warns you about the unsafely of such an
> operation.
> This is basic java stuff - you may want to have a look at a java 1.5
> tutorial.
> Eclipse has nothing to do with it.
>
> /adam
|
|
|
Powered by
FUDForum. Page generated in 0.34127 seconds