Inspectopedia 2024.3 Help

Constructor with too many parameters

Reports constructors whose number of parameters exceeds the specified maximum. Such objects are hard to instantiate, especially if some parameters are optional. Constructors with too many parameters may indicate that refactoring is necessary. Consider applying the builder pattern, for example.

Example:

public BankAccount(long accountNumber, String owner, double balance, double interestRate) { // fields initialization }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

ConstructorWithTooManyParameters
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Method metrics

Configure the inspection:

  • Use the Parameter limit field to specify the maximum allowed number of parameters in a constructor.

  • Use the Ignore constructors with visibility list to specify whether the inspection should ignore constructors with specific visibility.

Inspection options

Here you can find the description of settings available for the Constructor with too many parameters inspection, and the reference of their default values.

Parameter limit

5

Ignore constructors with visibility

Default setting: none

Other available settings:

  • private

  • package-private & private

  • protected, package-private & private

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.3, Qodana for JVM 2024.3,

Can be installed with plugin:

Java, 243.23126

Last modified: 03 December 2024