Inspectopedia 2025.2 Help

'Comparator' combinator can be used

Reports Comparator instances defined as lambda expressions that could be expressed using Comparator.comparing() calls. Chained comparisons which can be replaced by Comparator.thenComparing() expression are also reported.

Example:

myList.sort((person1, person2) -> person1.getName().compareTo(person2.getName())); myList2.sort((person1, person2) -> { int res = person1.first().compareTo(person2.first()); if(res == 0) res = person1.second().compareTo(person2.second()); if(res == 0) res = person1.third() - person2.third(); return res; });

After the quick-fixes are applied:

myList.sort(Comparator.comparing(Person::getName)); myList2.sort(Comparator.comparing(Person::first) .thenComparing(Person::second) .thenComparingInt(Person::third));

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

ComparatorCombinators
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Java language level migration aids | Java 8

This inspection depends on the Java feature 'Lambda expressions', which is available since Java 8.

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection ComparatorCombinators

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2025.2, Qodana for JVM 2025.2,

Last modified: 18 September 2025