EXPRESSIONS
Simple Assignment Operator
=
15.25.1
N
If
T
 is a reference type, then
SC
 may not be the same as
T
, but rather a type
that extends or implements
TC
. Let
RC
 be the class of the object referred to
by the value of the right hand operand at run time.
The compiler may be able to prove at compile time that the array compo 
nent will be of type
TC
 exactly (for example,
TC
 might be
final
). But if the
compiler cannot prove at compile time that the array component will be of
type
TC
 exactly, then a check must be performed at run time to ensure that
the class
RC
 is assignment compatible ( 5.2) with the actual type
SC
 of the
array component. This check is similar to a narrowing cast ( 5.4,  15.15),
except that if the check fails, an
ArrayStoreException
 is thrown rather
than a
ClassCastException
. Therefore:
O
If class
RC
 is not assignable to type
SC
, then no assignment occurs and an
ArrayStoreException
 is thrown.
O
Otherwise, the reference value of the right hand operand is stored into the
selected array component.
The rules for assignment to an array component are illustrated by the following
example program:
class ArrayReferenceThrow extends RuntimeException { }
class IndexThrow extends RuntimeException { }
class RightHandSideThrow extends RuntimeException { }
class IllustrateSimpleArrayAssignment {
static Object[] objects = { new Object(), new Object() };
static Thread[] threads = { new Thread(), new Thread() };
static Object[] arrayThrow() {
throw new ArrayReferenceThrow();
}
static int indexThrow() { throw new IndexThrow(); }
static Thread rightThrow() {
throw new RightHandSideThrow();
}
static String name(Object q) {
String sq = q.getClass().getName();
int k = sq.lastIndexOf( . );
return (k < 0) ? sq : sq.substring(k+1);
}
static void testFour(Object[] x, int j, Object y) {
String sx = x == null ? "null" : name(x[0]) + "s";
String sy = name(y);
371






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