Replace constructor with factory method
AltEnter | Replace constructor with factory method
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 AltEnter.
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.
Before | After |
---|---|
|
|
This dialog appears when you invoke the Replace constructor with factory method refactoring.
Item | Description |
---|---|
Factory method name | Specify here the name for the factory method. |
In (fully qualified name) | Specify here the class, where the method will be created. |
Thanks for your feedback!