Enum enhancement

Giguere, Thierry thierry.giguere at bnc.ca
Fri Dec 7 14:58:44 UTC 2018


I do agree that Optional is the way to go!

Thierry Giguère
Conception logiciel - Zone Sécurisée
Gestion de la livraison TI / Gestion du patrimoine et opétation de courtage (Transit 3933-1)
Tél. : 514 412-6228
thierry.giguere at bnc.ca<mailto:thierry.giguere at bnc.ca>

Banque Nationale Groupe Financier
1155 Metcalfe, 4e étage Mtl (Qc), H3B 4S9
Transit 5107-1

CONFIDENTIALITÉ : Ce document est destiné uniquement à la personne ou à l'entité à qui il est adressé. L'information apparaissant dans ce document est de nature légalement privilégiée et confidentielle. Si vous n'êtes pas le destinataire visé ou la personne chargée de le remettre à son destinataire, vous êtes, par la présente, avisé que toute lecture, usage, copie ou communication du contenu de ce document est strictement interdit. De plus, vous êtes prié de communiquer avec l’expéditeur sans délai ou d’écrire à confidentialite at bnc.ca<mailto:confidentialite at bnc.ca> et de détruire ce document immédiatement.
CONFIDENTIALITY: This document is intended solely for the individual or entity to whom it is addressed. The information contained in this document is legally privileged and confidential. If you are not the intended recipient or the person responsible for delivering it to the intended recipient, you are hereby advised that you are strictly prohibited from reading, using, copying or disseminating the contents of this document. Please inform the sender immediately or write to confidentiality at nbc.ca<mailto:confidentiality at nbc.ca> and delete this document immediately.

From: Maurizio Cimadamore [mailto:maurizio.cimadamore at oracle.com]
Sent: December 7, 2018 9:55 AM
To: Tagir Valeev <amaembo at gmail.com>; Brian Goetz <brian.goetz at oracle.com>
Cc: amber-dev at openjdk.java.net; Giguere, Thierry <thierry.giguere at bnc.ca>
Subject: Re: Enum enhancement


EXPÉDITEUR EXTERNE :  Sois PRUDENT, en particulier avec les liens et les pièces jointes

EXTERNAL SENDER - Be CAUTIOUS, particularly with links and attachments

________________________________
On 07/12/2018 14:36, Tagir Valeev wrote: > As for (2) probably Optional findValue(String name) would be better, as > you may decide what to do if it's absent using all the optional API. I like this suggestion! Maurizio > > With best regards, > Tagir Valeev. > > пт, 7 дек. 2018 г., 21:28 Brian Goetz brian.goetz at oracle.com<mailto:brian.goetz at oracle.com>: > >> (1) is already tracked as >> >> https://bugs.openjdk.java.net/browse/JDK-8073381 >> >> It is not as "easy" as you think in that these enum methods are >> generated by the compiler, not as ordinary library code, but it's not >> prohibited. >> >> (2) is not unreasonable. As there's no language component to it, you >> could take this directly to corelibs-dev for further evaluation. >> >> On 12/7/2018 9:13 AM, Giguere, Thierry wrote: >>> Hello, >>> >>> Related to the follow link and JEP 301 >> : >>> >> http://mail.openjdk.java.net/pipermail/amber-spec-experts/2018-December/000876.html >>> What is also missing and long-time due for enum right now and could be >> added quickly is more methods: >>> 1) We need to be able to iterate efficiently on enum. Currently calling >> method T[] values() duplicate the internal array. Moreover you need to go >> through method Arrays.stream() to convert the newly created array to >> stream. Adding a stream() method and a forEach() method would help fix this >> problem. Optionally a iterator() method could be provided >>> Arrays.stream(MyEnum.values()).forEach(); >>> >>> could be replaced by something like : >>> >>> MyEnum.forEach(); >>> >>> And >>> >>> Arrays.stream(MyEnum.values()).map(... >>> >>> could be written : >>> >>> MyEnum.stream().map(... >>> >>> 2) T valueOfOrDefault : pretty much like getOrDefault of the map >> interface. This method don't throw exception and fallback on default value. >> That would ease use of enum in stream / lambda programming >>> @Nonnull >>> MyEnum myEnum = MyEnum.DEFAULT_VALUE; >>> >>> try { >>> myEnum = MyEnum.valueOf(...); >>> } catch (NullPointerException | IllegalArgumentException e) >> { >>> // Just keep going with on the default value >>> } >>> >>> Since exception are thrown it doesn't fit very well in stream / lambda >> usage. Something like this : >>> MyData.stream().map(MyEnum::valueOf).forEach() >>> >>> Must be converted to : >>> >>> MyData.stream().map(d -> { >>> try { >>> return >> MyEnum.valueOf(...); >>> } catch (Exception e) { >>> return >> MyEnum.DEFAULT_VALUE; >>> } >>> }).forEach(); >>> >>> It would be great to write at least something like : >>> >>> MyData.stream().map(d -> MyEnum.valueOfOrDefault(d, >> MyEnum.DEFAULT_VALUE)).forEach(); >>> My feeling is these enhancement could be easily and quickly added >>> >>> Thierry Giguère >>> >>> CONFIDENTIALITÉ : Ce document est destiné uniquement à la personne ou à >> l'entité à qui il est adressé. L'information apparaissant dans ce document >> est de nature légalement privilégiée et confidentielle. Si vous n'êtes pas >> le destinataire visé ou la personne chargée de le remettre à son >> destinataire, vous êtes, par la présente, avisé que toute lecture, usage, >> copie ou communication du contenu de ce document est strictement interdit. >> De plus, vous êtes prié de communiquer avec l'expéditeur sans délai ou >> d'écrire à confidentialite at bnc.ca<mailto:confidentialite at bnc.ca> et de détruire ce document >> immédiatement. >>> CONFIDENTIALITY: This document is intended solely for the individual or >> entity to whom it is addressed. The information contained in this document >> is legally privileged and confidential. If you are not the intended >> recipient or the person responsible for delivering it to the intended >> recipient, you are hereby advised that you are strictly prohibited from >> reading, using, copying or disseminating the contents of this document. >> Please inform the sender immediately or write to confidentiality at nbc.ca<mailto:confidentiality at nbc.ca> >> and delete this document immediately. >>

CONFIDENTIALITÉ : Ce document est destiné uniquement à la personne ou à l'entité à qui il est adressé. L'information apparaissant dans ce document est de nature légalement privilégiée et confidentielle. Si vous n'êtes pas le destinataire visé ou la personne chargée de le remettre à son destinataire, vous êtes, par la présente, avisé que toute lecture, usage, copie ou communication du contenu de ce document est strictement interdit. De plus, vous êtes prié de communiquer avec l'expéditeur sans délai ou d'écrire à confidentialite at bnc.ca et de détruire ce document immédiatement.
CONFIDENTIALITY: This document is intended solely for the individual or entity to whom it is addressed. The information contained in this document is legally privileged and confidential. If you are not the intended recipient or the person responsible for delivering it to the intended recipient, you are hereby advised that you are strictly prohibited from reading, using, copying or disseminating the contents of this document. Please inform the sender immediately or write to confidentiality at nbc.ca and delete this document immediately.



More information about the amber-dev mailing list