pet*_*ust 1 java collections refactoring list
我有许多类的集合,我需要重构为新类.我在Eclipse或Netbeans中使用Java.目前,我使用委托List <Foo>创建新类FooList,然后按照代码无法编译的所有位置进行操作.有没有办法在不破坏代码的情况下执行此操作(最好是单个操作)?
编辑我有以下类型的构造:
public static List<Foo> Bar.createFooList(String s)
Run Code Online (Sandbox Code Playgroud)
并List<Foo>在其他地方经常使用,它作为业务对象是有意义的FooList.我手动完成了这个:
public class FooList {
private List<Foo> fooList;
public FooList(String s) {
createList(s);
}
private void createList(String s) {//...}
public int size() {return fooList.size();}
}
Run Code Online (Sandbox Code Playgroud)
FooList还将包含List之外的方法.例如现在:
Bar.normalize(List<Foo> fooList);
Run Code Online (Sandbox Code Playgroud)
然后会成为
fooList.normalize();
Run Code Online (Sandbox Code Playgroud)
其他函数需要List I的方法时,我使用Eclipse中的Source | Generate Delegate Methods选项在FooList中生成这些方法(与上面的size()一样).
我可以看到实现List <Foo>的吸引力@JonSkeet,但我看不出如何自动更改我的所有代码.
有没有理由不做FooList 工具 List<Foo>?