Draft Spec for Second Preview of Flexible Constructor Bodies (JEP 482)
Stephan Herrmann
stephan.herrmann at berlin.de
Tue May 28 17:20:00 UTC 2024
Hi Gavin,
One remark, one question:
In §8.8.7.1 it says:
"References to instance variables of class C are disallowed ..."
which seems to disqualify the following code:
public class C {
String name;
Test(C other) {
System.out.println(other.name);
super();
}
}
I assume this paragraph in italics is not normative, right? Later paragraphs are
clear that this applies to single name references and this references, but still
the above sentence seems misleading. The same applies for the next two sentences
(regarding other.foo(), or new other.Inner()).
Now for the question: two sentences from the previous edition have been removed,
but they seem to be needed, still:
* §8.1.3: "An instance of an anonymous class whose declaration occurs in a
pre-construction context (8.8.7.1) has no immediately enclosing instance."
* §15.9.2: "If C is an anonymous class, then:
o If the class instance creation expression occurs in a static context or a
pre-construction context, then i has no immediately enclosing instance.
Mention of "pre-construction context" removed.
Has this been moved to some other place, is it covered by some other rule
(which?), or was removal of those parts from §8.1.3 and §15.9.2 unintentional
after all?
thanks
Stephan
Am 15.05.24 um 00:13 schrieb Gavin Bierman:
> Dear experts:
>
> The first draft of a spec covering JEP 482 (Flexible Constructor Bodies (Second
> Preview)) is available at:
>
> https://cr.openjdk.org/~gbierman/jep482/latest/
> <https://cr.openjdk.org/~gbierman/jep482/latest/>
>
> Feel free to contact me directly or on this list with any comments/corrections.
>
> Thanks,
> Gavin
>
>> On 14 May 2024, at 20:04, Mark Reinhold <mark.reinhold at oracle.com> wrote:
>>
>> https://openjdk.org/jeps/482
>>
>> Summary: In constructors in the Java programming language, allow
>> statements to appear before an explicit constructor invocation, i.e.,
>> super(..) or this(..). The statements cannot reference the instance
>> under construction, but they can initialize its fields. Initializing
>> fields before invoking another constructor makes a class more reliable
>> when methods are overridden. This is a preview language feature.
>>
>> - Mark
More information about the amber-spec-experts
mailing list