Chained method calls
Reports method calls whose target is another method call. The quick-fix suggests to introduce a local variable.
Example:
class X {
int foo(File f) {
return f.getName().length();
}
}
After the quick-fix is applied:
class X {
int foo(File f) {
final String name = f.getName();
return name.length();
}
}
Use the inspection options to toggle warnings for the following cases:
chained method calls in field initializers, for instance,
private final int i = new Random().nextInt();
chained method calls operating on the same type, for instance,
new StringBuilder().append("x: ").append(new X()).append("y: ").append(new Y()).toString();
.
Inspection options
Option | Type | Default |
---|---|---|
Ignore chained method calls in field initializers | Checkbox | true |
Ignore calls to methods returning the same type as their enclosing class | Checkbox | true |
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |
Last modified: 13 July 2023