From gavin.bierman at oracle.com Fri Nov 1 16:04:28 2024 From: gavin.bierman at oracle.com (Gavin Bierman) Date: Fri, 1 Nov 2024 16:04:28 +0000 Subject: New candidate JEP: 492: Flexible Constructor Bodies (Third Preview) In-Reply-To: <20241002131430.EBCC577CE34@eggemoggin.niobe.net> References: <20241002131430.EBCC577CE34@eggemoggin.niobe.net> Message-ID: <2C1DE5FA-44F5-4D80-81F2-90BF21574EC4@oracle.com> Dear experts: The first draft of a spec covering JEP 492: Flexible Constructor Bodies (Third Preview) is available: https://cr.openjdk.org/~gbierman/jep492/latest/ (As the feature is unchanged from the second preview, this spec is the same as the previous edition but with a small number of minor bugfixes.) Feel free to contact me directly or on this list with any comments. Thanks Gavin On 2 Oct 2024, at 14:14, Mark Reinhold wrote: https://openjdk.org/jeps/492 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From maurizio.cimadamore at oracle.com Mon Nov 4 11:29:31 2024 From: maurizio.cimadamore at oracle.com (Maurizio Cimadamore) Date: Mon, 4 Nov 2024 11:29:31 +0000 Subject: New candidate JEP: 492: Flexible Constructor Bodies (Third Preview) In-Reply-To: <2C1DE5FA-44F5-4D80-81F2-90BF21574EC4@oracle.com> References: <20241002131430.EBCC577CE34@eggemoggin.niobe.net> <2C1DE5FA-44F5-4D80-81F2-90BF21574EC4@oracle.com> Message-ID: Hi Gavin, the changes look good, thanks! Some minor comments below: * "If a constructor body does not begin with contain an explicit constructor invocation and the constructor being declared is not part of the primordial class Object, then the constructor body implicitly begins with a superclass constructor invocation "super();", an invocation of the constructor of its the direct superclass that takes no arguments." Should we use the newly introduced terminology here (to make things extra clear)? E.g. say that if the constructor does not contain an explicit constructor invocation, then all statements are implicitly treated as epilogue, there's no prologue, and the explicit constructor is "super()". * "It is a compile-time error for a constructor to directly or indirectly invoke itself through a series of one or more alternate constructor invocations." I found this confusing -- after all constructor of A can do "new B()" which can then do "new A()". Does the constructor invoke itself? I think you mean "invoke itself _on the same receiver object_" ? * The fixes to 8.8.7.1 and 15.9.2 look good! (the PR for them is in [1]) Maurizio On 01/11/2024 16:04, Gavin Bierman wrote: > Dear experts: > > The first draft of a spec covering JEP 492: Flexible Constructor > Bodies (Third Preview) is available: > > https://cr.openjdk.org/~gbierman/jep492/latest/ > > (As the feature is unchanged from the second preview, this spec is the > same as the previous edition but with a small number of minor bugfixes.) > > Feel free to contact me directly or on this list with any comments. > > Thanks > Gavin > > >> On 2 Oct 2024, at 14:14, Mark Reinhold wrote: >> >> https://openjdk.org/jeps/492 >> >> ?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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gavin.bierman at oracle.com Mon Nov 4 12:23:39 2024 From: gavin.bierman at oracle.com (Gavin Bierman) Date: Mon, 4 Nov 2024 12:23:39 +0000 Subject: New candidate JEP: 492: Flexible Constructor Bodies (Third Preview) In-Reply-To: References: <20241002131430.EBCC577CE34@eggemoggin.niobe.net> <2C1DE5FA-44F5-4D80-81F2-90BF21574EC4@oracle.com> Message-ID: <56E680CD-C7E8-4516-A21C-DBF2030BBC0A@oracle.com> Thanks Maurizio. On 4 Nov 2024, at 11:29, Maurizio Cimadamore wrote: Hi Gavin, the changes look good, thanks! Some minor comments below: * "If a constructor body does not begin with contain an explicit constructor invocation and the constructor being declared is not part of the primordial class Object, then the constructor body implicitly begins with a superclass constructor invocation "super();", an invocation of the constructor of its the direct superclass that takes no arguments." Should we use the newly introduced terminology here (to make things extra clear)? E.g. say that if the constructor does not contain an explicit constructor invocation, then all statements are implicitly treated as epilogue, there's no prologue, and the explicit constructor is "super()". Thanks! Yes we should do this. I have updated the spec. * "It is a compile-time error for a constructor to directly or indirectly invoke itself through a series of one or more alternate constructor invocations." I found this confusing -- after all constructor of A can do "new B()" which can then do "new A()". Does the constructor invoke itself? I think you mean "invoke itself _on the same receiver object_" ? This is actually text that got moved from 8.8.7.1; so dates from prehistory :-) I think it is okay. It means that you can?t do a this( ?) [that?s invoking a constructor] that is actually calling yourself; or if you call another constructor, then you can?t have a chain of this invocations that end up calling you. A new expression isn?t considered an invocation. * The fixes to 8.8.7.1 and 15.9.2 look good! (the PR for them is in [1]) Yay. Thanks, Gavin -------------- next part -------------- An HTML attachment was scrubbed... URL: