Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refactor variable type in Eclipse?

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 promotion to long would cause dependent variables to change their types also:

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

?

like image 293
Stepan Yakovenko Avatar asked Mar 03 '11 19:03

Stepan Yakovenko


People also ask

How do I Refactor a variable in Eclipse?

You can Also Press Alt+Shift+R in Eclipse to refactor on variable.

How do I change the datatype of a variable in Eclipse?

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. To make it a bit faster, you can navigate to the previous/next error with ctrl + , / ctrl + . .


1 Answers

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.

like image 83
Zds Avatar answered Sep 20 '22 14:09

Zds