No. down casting will give a compile time error, if it is not cast
explicitly.
 
-----Original Message----- 
From: Fewtrell, Tom 
To: JDJList 
Sent: 5/7/02 12:29 PM 
Subject: [jdjlist] RE: R�f. : [jdjlist] casting 
 
Yes, as I understand it up-casting to a base class is okay as you can 
guarantee that the class being cast implements the methods defined by 
the 
class it extends (or interface it implements). There is no such 
guarantee 
with down-casting where the behaviour/attributes of the class you are 
casting to is likely to go beyond that of the class you are casting. 
 
Casting 'up' or 'down' of course refers to moving up or down the 
hereditary 
tree created by inheritance- I know initially I found it confusing that 
'casting up' involved (potentially) reducing the behaviour of a class. 
 
I think 'down casting' is legal in that it is not caught by the compiler 
but 
may cause runtime exceptions (ClassCastException)- someone let me know 
if 
this is wrong :) 
 
Tom  
 
-----Original Message----- 
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, May 07, 2002 11:09 AM 
To: JDJList 
Subject: [jdjlist] R�f. : [jdjlist] casting 
 
 
 
Hello 
 
It's java basic.  It's a up and down casting system.  It's a notion from 
C++. 
You can always up-casting but down-casting it's very dangerous. 
 
regards 
 
 
------------------------------------------------------------------------ 
---- 
--------------------------------- 
 
St�phane PURNELLE                         [EMAIL PROTECTED] 
Service Informatique       Corman S.A.           Tel : 00 32 087/342 220 
 
 
To change your membership options, refer to: 
http://www.sys-con.com/java/list.cfm 
 
This e-mail and any attachment is for authorised use by the intended 
recipient(s) only.  It may contain proprietary material, confidential 
information and/or be subject to legal privilege.  It should not be 
copied, disclosed to, retained or used by, any other party.  If you are 
not an intended recipient then please promptly delete this e-mail and 
any attachment and all copies and inform the sender.  Thank you. 
 
To change your membership options, refer to: 
http://www.sys-con.com/java/list.cfm 

To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

Reply via email to