Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to safe change the type of a variable intellij?

Suppose I have a class like this.

Public class MyClass{
    private String id;

    public Myclass(String id){
        this.id = id;
    }

    public String getId(){
        return id;
    }

    public void setId(String id){
        this.id = id;
    }
}

And suddenly I want to change the type of id into Integer. Is there a way to do that with intellij without breaking usages?

like image 822
Supun Wijerathne Avatar asked Jul 18 '16 03:07

Supun Wijerathne


People also ask

How do I change all instances of a variable in IntelliJ?

Try to set cursor on variable and use shortcut Shift-F6 - after that there are dialog frame for change name of variable and it changes all occurences of variable to setted name.

How do I refactor in IntelliJ?

Invoke refactoring Select an item to refactor. You can select a file/folder in the Project tool window or expression/symbol in the editor. Press Ctrl+Alt+Shift+T to open a list of refactorings that can be selected. Alternatively, you can use a keyboard shortcut for a specific refactoring.

How do I set variables in IntelliJ?

Add environment variables From the main menu, select Run | Edit Configurations or choose Edit Configurations from the run/debug configurations selector on the toolbar. In the Run/Debug Configurations dialog, select a configuration you want to add the environment variables to.


1 Answers

Highlight the type of field and press Ctrl+Shift+F6

or

Highlight the type of field, Right-Click -> Refactor -> Type migration

or

Highlight the type of field, Menu -> Refactor -> Type migration

like image 169
Rahul Teotia Avatar answered Sep 23 '22 04:09

Rahul Teotia