How can I refactor(move) a Java method in classA into classB and have all references to the method to it updated?
Is this supported in Eclipse ?
解决方案
For a static method, you can right click and select 'Move'.
Obj1.myMethod()
would then get 'moved' to
Obj2.myMethod()
and eclipse would fix your imports etc.
For a non-static method, this may not work depending on the relationship between classA and classB.
Obj1 myobj1 = new Obj1();
myobj1.myMethod();
myobj1.myOtherMethod();
If you move myMethod() to a different class, the refactoring would have to change the object initialization. If myOtherMethod isn't getting moved, then it can't just change the type of myobj1 to Obj2 because then myOtherMethod won't work.