Inspectopedia Help

Expression with 'java.time' 'compareTo()' call can be simplified

Reports java.time comparisons with compareTo() calls that can be replaced with isAfter(), isBefore() or isEqual() calls.

Example:

LocalDate date1 = LocalDate.now(); LocalDate date2 = LocalDate.now(); boolean t = date1.compareTo(date2) > 0;

After the quick-fix is applied:

LocalDate date1 = LocalDate.now(); LocalDate date2 = LocalDate.now(); boolean t = date1.isAfter(date2);

New in 2022.3

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023