16
C H A P T E R
Definite Assignment
All the evolution we know of proceeds from the vague to the definite.
 Charles Peirce
E
ACH local variable must have a
definitely assigned
 value when any access of
its value occurs. An access to its value consists of the simple name of the variable
occurring anywhere in an expression except as the left hand operand of the simple
assignment operator
=
.
A Java compiler must carry out a specific conservative flow analysis to make
sure that, for every access of a local variable, the local variable is definitely
assigned before the access; otherwise a compile time error must occur.
The remainder of this chapter is devoted to a precise explanation of the words
 definitely assigned before . The idea is that an assignment to the local variable
must occur on every possible execution path to the access from the beginning of
the constructor, method, or static initializer that contains the access. The analysis
takes into account the structure of statements and expressions; it also provides a
special treatment of the expression operators
!
,
&&
,
||
, and
? :
, the operators
&
,
|
,
^
,
==
, and
!=
 with
boolean
 operands, and boolean valued constant expressions.
For example, a Java compiler recognizes that
k
 is definitely assigned before its
access (as an argument of a method invocation) in the code:
{
int k;
if (v > 0 && (k = System.in.read()) >= 0)
System.out.println(k);
}
because the access occurs only if the value of the expression:
v > 0 && (k = System.in.read()) >= 0
is true, and the value can be
true
 only if the assignment to
k
 is executed (more
properly, evaluated). Similarly, a Java compiler will recognize that in the code:
383






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