Skip to main content



      Home
Home » Newcomers » Newcomers » another type safety warning with generics
another type safety warning with generics [message #115000] Sat, 05 November 2005 21:18 Go to next message
Eclipse UserFriend
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 #115120 is a reply to message #115000] Sun, 06 November 2005 23:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: akiezun.remove.mit.edu

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
Re: another type safety warning with generics [message #115355 is a reply to message #115120] Mon, 07 November 2005 16:14 Go to previous message
Eclipse UserFriend
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
Previous Topic:Configuring Eclipse to compile with GCJ
Next Topic:New to J2EE
Goto Forum:
  


Current Time: Fri Jul 18 00:43:04 EDT 2025

Powered by FUDForum. Page generated in 0.34127 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top