-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
9, 10
A DESCRIPTION OF THE REQUEST :
There isn't a good way to create an anonymous Comparator instance for arrays based on a property of the array object.
For example if you have an array of Potatoes and you want to compare them using their weigth as comparable object, this is not easily possible.
JUSTIFICATION :
It's currently very ugly to create a anonymous Comparator class to compare arrays based on a key.
For "normal" Objects this is possible using Comparator#comparing(Function, Comparator), not so much for arrays or any other type of collection
There really should be a convinience method like all the other default convinience thenComaring methods implemented by the comparator interface
CUSTOMER SUBMITTED WORKAROUND :
With Java 9 the following should work:
(array1, array2) -> Arrays.compare(array1, array2, Comparator.comparing(Function))
There isn't a good way to create an anonymous Comparator instance for arrays based on a property of the array object.
For example if you have an array of Potatoes and you want to compare them using their weigth as comparable object, this is not easily possible.
JUSTIFICATION :
It's currently very ugly to create a anonymous Comparator class to compare arrays based on a key.
For "normal" Objects this is possible using Comparator#comparing(Function, Comparator), not so much for arrays or any other type of collection
There really should be a convinience method like all the other default convinience thenComaring methods implemented by the comparator interface
CUSTOMER SUBMITTED WORKAROUND :
With Java 9 the following should work:
(array1, array2) -> Arrays.compare(array1, array2, Comparator.comparing(Function))
- relates to
-
JDK-8184694 add lexicographic comparator methods for collections
-
- Open
-