An instance scope expression evaluates a
subexpression in the context of an
instance scope. Their use is comparable
to the with
-statement of the Basic and Pascal
programming languages.
Instance Scope Expressions | |||||
---|---|---|---|---|---|
|
The compile-time type of the expression e
to the left of the period
has to be a reference type, or a compile-time error
occurs. The evaluation proceeds in several steps:
The expression e
is evaluated.
If the result is null
,
a NullPointerException
is thrown.
The result is assigned to a final
local variable
i
which is implicitly declared by the
instance scope expression and has the compile-time type of
e
. The scope of i
is the parenthesised expression. Its name is the special identifier
$
if no local variable of that name is in scope,
or an internal name which cannot conflict with legal identifiers.
The right expression is evaluated, its result is discarded. Within this
expression, all field and method members of the compile-time type of
i
are in scope.
Type and result of the instance scope expression are those of
i
.
The following are examples for instance scope expressions:
container.add(new JCheckBox("foo").(setHorizontalAlignment(bar), setFont(myFont))); System.out.(println(line1), println(line2), println(line3));