Java Reference
In-Depth Information
15.11. Field Access Expressions
A field access expression may access a field of an object or array, a reference to which is
the value of either an expression or the special keyword
super
.
FieldAccess:
Primary
.
Identifier
super .
Identifier
ClassName
. super .
Identifier
The meaning of a field access expression is determined using the same rules as for qualified
type, or interface type.
It is also possible to refer to a field of the current instance or current class by using a simple
15.11.1. Field Access Using a Primary
The type of the
Primary
must be a reference type
T
, or a compile-time error occurs.
The meaning of the field access expression is determined as follows:
• If the identifier names several accessible (§
6.6
) member fields in type
T
, then the
field access is ambiguous and a compile-time error occurs.
• If the identifier does not name an accessible member field in type
T
, then the field
access is undefined and a compile-time error occurs.
• Otherwise, the identifier names a single accessible member field in type
T
, and the
type of the field access expression is the type of the member field after capture
conversion (§
5.1.10
).
At run time, the result of the field access expression is computed as follows: (assuming that
the program is correct with respect to definite assignment analysis, i.e. every blank
final
variable is definitely assigned before access)
• If the field is
static
:
♦ The
Primary
expression is evaluated, and the result is discarded. If evaluation
of the
Primary
expression completes abruptly, the field access expression
completes abruptly for the same reason.