Converts a field to a read-only field. Read-only fields can be initialized either at the declaration or in a constructor, which prevents the field value from the occasional overwriting.
Available when the cursor is on a field declaration, provided that its value never changes.
Place the caret on a field declaration.
The blinking cursor shows the caret’s position at which the Refactoring is available.
- Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
- Select Make Read-Only from the menu.
After execution, the Refactoring adds the readonly modifier to the field declaration.