Replace constructor with factory method
Last modified: 10 August 2022note
This refactoring is available only as an intention action.
The Replace Constructor With Factory Method refactoring lets you hide a constructor and replace it with a static method which returns a new instance of a class.
Place the caret at the class constructor in the editor and press Alt+Enter.
From the list of available context actions, select Replace constructor with factory method.
In the dialog that opens, specify the name of the factory method and the class where the method should be created.
Preview and apply the changes.
Example
Before | After |
---|---|
|
|
Thanks for your feedback!
Was this page helpful?