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
}
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
Option | Type | Default |
---|---|---|
Parameter limit | Number | 5 |
Ignore constructors with visibility | Dropdown | none |
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |
Last modified: 13 July 2023