New JEP: Concise Method Bodies
forax at univ-mlv.fr
forax at univ-mlv.fr
Tue Oct 9 19:34:55 UTC 2018
> De: "Kevin Bourrillion" <kevinb at google.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "daniel smith" <daniel.smith at oracle.com>, "amber-spec-experts"
> <amber-spec-experts at openjdk.java.net>
> Envoyé: Mardi 9 Octobre 2018 21:03:42
> Objet: Re: New JEP: Concise Method Bodies
> I do like that feature, but, aren't statics the only things that are already
> easy to make lazy (holder class)?
> This pattern should already be evangelized heavily today for anyone with Java 8
> and up.
The holder class is a great pattern until you have a better one (sorry just kidding).
The holder class means you create a supplementary class and a class object + metadata in not something very lightweight in memory (and on disc) and you still have to hold a lock the first time you call it (the lock around the static init). If the initialization of the constant has no side effect, we can re-use another mechanism than the lazy initialization of the class, the lazy initialization of the constant of the constant pool aka constant dynamic.
The other advantages of the lazy static final is that it is binary backward compatible with the static final so you can choose if a static final is lazy or not whenever you want at no cost.
> On Tue, Oct 9, 2018 at 11:50 AM < [ mailto:forax at univ-mlv.fr | forax at univ-mlv.fr
> ] > wrote:
>>> De: "Kevin Bourrillion" < [ mailto:kevinb at google.com | kevinb at google.com ] >
>>> À: "daniel smith" < [ mailto:daniel.smith at oracle.com | daniel.smith at oracle.com ]
>>> Cc: "Remi Forax" < [ mailto:forax at univ-mlv.fr | forax at univ-mlv.fr ] >,
>>> "amber-spec-experts" < [ mailto:amber-spec-experts at openjdk.java.net |
>>> amber-spec-experts at openjdk.java.net ] >
>>> Envoyé: Mardi 9 Octobre 2018 20:48:10
>>> Objet: Re: New JEP: Concise Method Bodies
>>> On Tue, Oct 9, 2018 at 11:43 AM Dan Smith < [ mailto:daniel.smith at oracle.com |
>>> daniel.smith at oracle.com ] > wrote:
>>>> We have a rich API for building Comparators. I would expect most non-legacy
>>>> implementations of Comparable to implement their 'compareTo' method by
>>>> delegating to a Comparator.
>>> To me, this pattern is the strongest use case for the entire feature.
>> We need the lazy static final feature too.
> Kevin Bourrillion | Java Librarian | Google, Inc. | [ mailto:kevinb at google.com |
> kevinb at google.com ]
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the amber-spec-experts