Draft JLS spec for records
Tagir Valeev
amaembo at gmail.com
Wed Sep 4 05:21:48 UTC 2019
Hello!
> I also believe we should make the instance initializer illegal in record
given that a require initializer is a kind a better instance initializer
because it can access local variables.
I don't think so. A compact constructor (or require initializer, as you
propose) could be not the only constructor. An instance initializer is
convenient because it's added to every constructor, regardless of whether
it's compact or not. So the new thing doesn't supersede the instance
initializer and I see no good reason to explicitly disable it.
With best regards,
Tagir Valeev.
On Tue, Sep 3, 2019 at 7:02 PM <forax at univ-mlv.fr> wrote:
>
>
> ------------------------------
>
> *De: *"Gavin Bierman" <gavin.bierman at oracle.com>
> *À: *"Remi Forax" <forax at univ-mlv.fr>
> *Cc: *"Brian Goetz" <brian.goetz at oracle.com>, "amber-spec-experts" <
> amber-spec-experts at openjdk.java.net>
> *Envoyé: *Mardi 3 Septembre 2019 12:37:17
> *Objet: *Re: Draft JLS spec for records
>
>
> Thanks Remi.
>
> - a canonical constructor can not have throws clause (from the text of
> the section) but the grammar in 8.10.2 the CompactConstructor declaration
> can have a throw clause ?
>
>
> That is just a typo - thanks. The rest I will get back to you shortly.
>
>
> humm,
> thinking more about the canonical constructor
> - does'nt really need a modifier (it's always public if you believe the
> current state of the spec or it's the one of the record anyway)
> - doesn't need to declare a type parameter
> - doesn't need annotations because you get the one from the record
> so it's more like an initializer than a constructor.
>
> Given that i've always find the syntax of the canonical constructor too
> close to the one of the real constructor (depending on the fact that
> parenthesis are present or not),
> i propose a new kind of initializer, the require initializer (obvisouly it
> can be another name than "require").
>
> An example of syntax:
> record Foo(String s) {
> require {
> Objects.requireNonNull(s);
> }
> }
>
> I also believe we should make the instance initializer illegal in record
> given that a require initializer is a kind a better instance initializer
> because it can access local variables.
>
> An example that should not compile
> record Foo(String s) {
> require {
> System.out.println("am i print first ?");
> }
> {
> System.out.println("am i print first ?");
> }
> }
>
>
>
> Thanks,
> Gavin
>
>
>
> Rémi
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20190904/9746aa43/attachment.html>
More information about the amber-spec-experts
mailing list