Inspectopedia Help

Chained method calls

Reports method calls whose target is another method call. The quick-fix suggests to introduce a local variable.


class X { int foo(File f) { return f.getName().length(); } }
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

Here you can find the description of settings available for the Chained method calls inspection, and the reference of their default values.

Ignore chained method calls in field initializers

Default: Selected

Ignore calls to methods returning the same type as their enclosing class

Default: Selected

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Java, 241.14841

Last modified: 12 March 2024