The Convert Method to Property refactoring converts non-void methods without parameters to read properties, and void methods with exactly one parameter to write properties.
- Place the caret at the name of the method in Class View, Object Browser, or in the code editor.
- On the main menu or context menu, choose Refactor | Convert Method to Property.
- In the dialog box that opens, specify a property name:
- Click OK to change the selected method to a read or a write property. At the same time, all method calls will be substituted with the corresponding property accesses.
Consider the following example:
After changing the method
setX to a write property
X the code looks as follows: