Java Reference
In-Depth Information
method invocation. Then the target reference is the
n
'th lexically enclosing in-
It is a compile-time error if the
n
'th lexically enclosing instance (§
8.1.3
) of
this
does not exist.
• If the
MethodName
is a qualified name of the form
TypeName
.
Identifier
, then
there is no target reference.
• If the
MethodName
is a qualified name of the form
FieldName
.
Identifier
, then
there are two subcases:
♦ If the invocation mode is
static
, then there is no target reference. The expres-
sion
FieldName
is evaluated, but the result is then discarded.
♦ Otherwise, the target reference is the value of the expression
FieldName
.
2.
If the second production for
MethodInvocation
, which includes a
Primary
, is in-
volved, then there are two subcases:
• If the invocation mode is
static
, then there is no target reference. The expression
Primary
is evaluated, but the result is then discarded.
• Otherwise, the expression
Primary
is evaluated and the result is used as the tar-
get reference.
In either case, if the evaluation of the
Primary
expression completes abruptly, then
no part of any argument expression appears to have been evaluated, and the meth-
od invocation completes abruptly for the same reason.
3.
If the third production for
MethodInvocation
, which includes the keyword
super
, is
involved, then the target reference is the value of
this
.
4.
If the fourth production for
MethodInvocation
,
ClassName
. super
, is involved, then
the target reference is the value of
ClassName
.this
.
5.
If the fifth production for
MethodInvocation
, beginning with
TypeName
.
NonWildTypeArguments
, is involved, then there is no target reference.
Example 15.12.4.1-1. Target References and
static
Methods
When a target reference is computed and then discarded because the invocation mode
is
static
, the reference is not examined to see whether it is
null
:
class Test1 {
static void mountain() {
System.out.println("Monadnock");