Re: why this cast won't work?
- From: Roedy Green <my_email_is_posted_on_my_website@xxxxxxxxxxxxxx>
- Date: Sun, 30 Oct 2005 07:17:09 GMT
On Sat, 29 Oct 2005 15:55:53 GMT, Jack <none@xxxxxxxx> wrote, quoted
or indirectly quoted someone who said :
> ServerSocket server = new ServerSocket(80);
> CastSocket cs = (CastSocket)server.accept();
Whenever you are puzzled by a run time cast exception you can write
some code like this:
Object cs = server.accept();
System.out.println( cs.getClass() );
Casting the rereference to what you are actually getting will work, an
interface it supports, or a superclass of it, but nothing else.
You can't change it into anything else with a reference cast. You
can't cast it into something it is not already.
You can with (int) somelong convert a long to an int, however.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
.
- Prev by Date: Re: Open Source English Language Parser
- Next by Date: Re: Animation jargon
- Previous by thread: Re: why this cast won't work?
- Next by thread: Animated PNGs?
- Index(es):
Relevant Pages
|