Skip to main content
edited tags
Link
Sotirios Delimanolis
  • 280.9k
  • 62
  • 718
  • 744
Post Closed as "Needs details or clarity" by OldProgrammer, Holger, Sotirios Delimanolis
added 112 characters in body
Source Link
Aqeel Ashiq
  • 2.2k
  • 7
  • 29
  • 60

In short the question is how can we find inside compare method of Comparator implementation whether sort order is ascending (simple) or descending (reversed). One method I found is to place instanceof check for ReverseOrder class. But that is highly unreliable, as there are many implementations of Comparator class for reverse order.

In other words, what if we have to write a comparator, which should not allow reversed(or descending) order.

In short the question is how can we find inside compare method of Comparator implementation whether sort order is ascending (simple) or descending (reversed). One method I found is to place instanceof check for ReverseOrder class. But that is highly unreliable, as there are many implementations of Comparator class for reverse order.

In short the question is how can we find inside compare method of Comparator implementation whether sort order is ascending (simple) or descending (reversed). One method I found is to place instanceof check for ReverseOrder class. But that is highly unreliable, as there are many implementations of Comparator class for reverse order.

In other words, what if we have to write a comparator, which should not allow reversed(or descending) order.

Source Link
Aqeel Ashiq
  • 2.2k
  • 7
  • 29
  • 60

How to find sort order in compare method Java

In short the question is how can we find inside compare method of Comparator implementation whether sort order is ascending (simple) or descending (reversed). One method I found is to place instanceof check for ReverseOrder class. But that is highly unreliable, as there are many implementations of Comparator class for reverse order.