Convert to Instance Method
Last modified: 10 August 2022Convert to Instance Method refactoring lets you convert a static method to a non-static, class instance method, with a class being the type parameter of the initial method.
tip
This refactoring is also available from UML Class diagram.
In the editor, place the caret at the declaration or usage of a method that you want to refactor. The method should be
static
and the types of its parameters should be the classes from the project. Also note that you cannot use such parameters types asString
.From the main menu, select Refactor | Convert to Instance Method.
You can also use a context menu to access this refactoring.
In the dialog that opens, select the class you want the method to belong to after the conversion. All the usages of this class inside the method are replaced with this.
If you need, change the visibility scope of the converted method.
Preview and apply changes.
Example
Consider classes MyClass
, ClassB
and ClassB
residing in the same package.
As a result, MyClass
and ClassB
become converted.
Before | After |
---|---|
|
|
Thanks for your feedback!