Java Reference
In-Depth Information
If the declaration declares a final variable which is definitely assigned before the simple ex-
pression, the meaning of the name is the value of that variable. Otherwise, the meaning of
the expression name is the variable declared by the declaration.
If the expression name appears in a context where it is subject to assignment conversion
or method invocation conversion or casting conversion, then the type of the expression
name is the declared type of the field, local variable, or parameter after capture conversion
5.1.10 ) .
Otherwise, the type of the expression name is the declared type of the field, local variable
or parameter.
That is, if the expression name appears “on the right hand side”, its type is subject to
capture conversion. If the expression name is a variable that appears “on the left hand
side”, its type is not subject to capture conversion.
Example 6.5.6.1-1. Simple Expression Names
Click here to view code image
class Test {
static int v;
static final int f = 3;
public static void main(String[] args) {
int i;
i = 1;
v = 2;
f = 33; // compile-time error
System.out.println(i + " " + v + " " + f);
}
}
In this program, the names used as the left-hand-sides in the assignments to i , v , and f
denote the local variable i , the field v , and the value of f (not the variable f , because f is
a final variable). The example therefore produces an error at compile time because the
last assignment does not have a variable as its left-hand side. If the erroneous assign-
ment is removed, the modified code can be compiled and it will produce the output:
1 2 3
6.5.6.2. Qualified Expression Names
If an expression name is of the form Q.Id , then Q has already been classified as a package
name, a type name, or an expression name.
Search WWH ::




Custom Search