Conditional can be pushed inside branch expression
Reports conditional expressions with then
and else
branches that are similar enough so that the expression can be moved inside. This action shortens the code.
Example:
double g(int a, int b) {
return a == b ? Math.cos(0) : Math.cos(1);
}
After the quick-fix is applied:
double g(int a, int b) {
return Math.cos(a == b ? 0 : 1);
}
New in 2017.2
Inspection options
Option | Type | Default |
---|---|---|
Ignore when conditional will be only argument of a method call | Checkbox | true |
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |
Last modified: 13 July 2023