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.
If you want to move the method to a new class - Refactor > Extract Class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With