Inspectopedia
 
2024.3

Chained method calls

Warning
New
Last modified: 03 December 2024

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

Example:

After the quick-fix is applied:

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();.