Java Reference
In-Depth Information
♦ A final field of a class type (which may be either a class variable or an instance
variable)
♦ The final field length of an array type
then Q.Id denotes the value of the field, unless it appears in a context that requires
a variable and the field is a definitely unassigned blank final field, in which case it
yields a variable.
The type of the expression Q.Id is the declared type of the field after capture con-
version (§ 5.1.10 ) .
If Q.Id appears in a context that requires a variable and not a value, and the field
denoted by Q.Id is definitely assigned, then a compile-time error occurs.
• Otherwise, Q.Id denotes a variable, the field Id of class T , which may be either a
class variable or an instance variable.
The type of the expression Q.Id is the type of the field member after capture con-
version (§ 5.1.10 ) .
Example 6.5.6.2-1. Qualified Expression Names
Click here to view code image
class Point {
int x, y;
static int nPoints;
}
class Test {
public static void main(String[] args) {
int i = 0;
i.x++; // compile-time error
Point p = new Point();
p.nPoints(); // compile-time error
}
}
This program encounters two compile-time errors, because the int variable i has no
members, and because nPoints is not a method of class Point .
Example 6.5.6.2-2. Qualifying an Expression with a Type Name
Note that expression names may be qualified by type names, but not by types in gen-
eral. A consequence is that it is not possible to access a class variable through a para-
meterized type.
Search WWH ::




Custom Search