Java – eclipse supports refactoring
•
Java
Can eclipse do this refactoring?
Suppose I have a class with a list:
class DomainObject { private List list; public List getList() { return list; } }
Then some code using this class needs to do this:
domainObject.getList().get(23);
I want to refactor (and let all other references do the same):
domainObject.get(23);
I tried some options, but it seems that I can't find a way (except manually)
Solution
Try this:
>Let domainobject correctly implement list (use list as delegate) > let getlist() return this > refactor inline getlist() > (optional) delete "implements list" again and keep the get() method
Another (simpler) option:
>Refactoring – rename getlist() to getmylistwithauniquenameacrosstheproject() (let eclipse update all references) > search – replace "getmylistwithauniquenameacrosstheproject()." Add and implement domainobject through "" > get(int)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码