5.5
Casting Conversion
CONVERSIONS AND PROMOTIONS
If
S
 is a class type:
N
If
T
 is a class type, then
S
 and
T
 must be related classes that is,
S
 and
T
must be the same class, or
S
 a subclass of
T
,
 or
T
 a subclass of
S
; otherwise
a compile time error occurs.
N
If
T
 is an interface type:
O
If
S
 is not a
final
 class ( 8.1.2), then the cast is always correct at com 
pile time (because even if
S
 does not implement
T
, a subclass of
S
 might).
O
If
S
 is a
final
 class ( 8.1.2), then
S
 must implement
T
, or a compile 
time error occurs.
N
If
T
 is an array type, then
S
 must be the class
Object
, or a compile time
error occurs.
If
S
 is an interface type:
N
If
T
 is a class type that is not
final
 ( 8.1.2), then the cast is always correct
at compile time (because even if
T
 does not implement
S
, a subclass of
T
might).
N
If
T
 is a class type that is
final
 ( 8.1.2), then
T
 must implement
S
, or a
compile time error occurs.
N
If
T
 is an interface type and if
T
 and
S
 contain methods with the same signa 
ture ( 8.4.2) but different return types, then a compile time error occurs.
If
S
 is an array type
SC[]
, that is, an array of components of type
SC
:
N
If
T
 is a class type, then if
T
 is not
Object
, then a compile time error occurs
(because
Object
 is the only class type to which arrays can be assigned).
N
If
T
 is an interface type, then a compile time error occurs unless
T
 is the
interface type
Cloneable
, the only interface implemented by arrays.
N
If
T
 is an array type
TC[]
, that is, an array of components of type
TC
, then a
compile time error occurs unless one of the following is true:
O
TC
 and
SC
 are the same primitive type.
O
TC
 and
SC
 are reference types and type
SC
 can be cast to
TC
 by a recursive
application of these compile time rules for casting.
See  8 for the detailed specifications of classes,  9 for interfaces, and  10 for
arrays.
68






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved