Feedback on records (JEP 359)

Anthony Vanelverdinghe anthonyv.be at outlook.com
Sun Apr 26 08:01:58 UTC 2020


On 25/04/2020 20:05, Anthony Vanelverdinghe wrote:
> Hi Brian
>
> On 25/04/2020 17:42, Brian Goetz wrote:
>> FWIW, most of the actual boilerplate in your above Comparator is 
>> folding in the null handling.  It might be an RFE on Comparator 
>> factories would be more effective in solving this problem, and also 
>> more useful (as it wouldn't only apply to records.)  If your 
>> comparator was (say)
>>
>>     Comparator.comparingNullable(YearMonth::year)
>> .thenComparingNullable(YearMonth::month);
>>
>> or similar, would you be as concerned?
> That would surely be helpful (I'll file a bug report for it), but I 
> believe `sorted-record` would still be useful.


For the record, I filed a slight variation of this idea as "Comparator: 
allow specifying nulls behavior alongside keyExtractor parameter" at 
https://bugs.openjdk.java.net/browse/JI-9064751
which would allow to write:

Comparator.comparing(YearMonth::year, Nulls.LAST)
         .thenComparing(YearMonth::month, Nulls.LAST);

where Nulls is an enum in Comparator with values FIRST, LAST, and THROW.

Kind regards,
Anthony



More information about the amber-dev mailing list