15.25.2
Compound Assignment Operators
EXPRESSIONS
Threads[throw]=throw => IndexThrow
Threads[throw]=StringBuffer => IndexThrow
Threads[1]=throw => RightHandSideThrow
Threads[1]=StringBuffer => ArrayStoreException
Threads[throw]=throw => IndexThrow
Threads[throw]=Thread => IndexThrow
Threads[1]=throw => RightHandSideThrow
Threads[1]=Thread => Okay!
Threads[throw]=throw => IndexThrow
Threads[throw]=StringBuffer => IndexThrow
Threads[9]=throw => RightHandSideThrow
Threads[9]=StringBuffer => IndexOutOfBoundsException
Threads[throw]=throw => IndexThrow
Threads[throw]=Thread => IndexThrow
Threads[9]=throw => RightHandSideThrow
Threads[9]=Thread => IndexOutOfBoundsException
The most interesting case of the lot is the one thirteenth from the end:
Threads[1]=StringBuffer => ArrayStoreException
which indicates that the attempt to store a reference to a
StringBuffer
 into an
array whose components are of type
Thread
 throws an
ArrayStoreException
.
The code is type correct at compile time: the assignment has a left hand side of
type
Object[]
 and a right hand side of type
Object
. At run time, the first actual
argument to method
testFour
 is a reference to an instance of  array of
Thread
and the third actual argument is a reference to an instance of class
StringBuffer
.
15.25.2   Compound Assignment Operators
All compound assignment operators require both operands to be of primitive type,
except for
+=
, which allows the right hand operand to be of any type if the left 
hand operand is of type
String
.
A compound assignment expression of the form
E1 op
=
E2
 is equivalent to
E1 = (T )((E1) op (E2))
, where
T
 is the type of
E1
, except that
E1
 is evaluated
only once. Note that the implied cast to type
T
 may be either an identity conver 
sion ( 5.1.1) or a narrowing primitive conversion ( 5.1.3). For example, the fol 
lowing code is correct:
short x = 3;
x += 4.6;
and results in
x
 having the value
7
 because it is equivalent to:
short x = 3;
x = (short)(x + 4.6);
374






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