How to refactor variable type in Eclipse?

前端 未结 3 1153
青春惊慌失措
青春惊慌失措 2020-12-09 07:17

I want to refactor code like this:

int x=4;
int y=x;
System.out.println(y);

How can i do this automatically in Eclipse so x\'s type promoti

3条回答
  •  执念已碎
    2020-12-09 08:08

    How I usually do is that I change one of the upstream variables to long. This causes Eclipse to give error from each assignment where you offer long instead of int. Then I just select ctrl-1 (Quick-fix) on each of them and pick "change variable x to long".

    This works when the new type is not directly assignable to the old one.

提交回复
热议问题