Eclipse是否有工具将类型层次结构合并到单个类中?



eclipse有工具可以从AB中创建Merged吗?

public class A {
    int a;
    public int getA(){
        return A;
    }
}

public class B extends A {
    int b;
    public int getB(){
        return b;
    }
}

public class Merged {
    int a;
    int b;
    public int getA(){
        return A;
    }
    public int getB(){
        return b;
    }
}

我不这么认为。这不是那么简单的任务。你的例子很简单,但是考虑一下:

class A {
    private int a;
    public void foo(){
        System.out.println(a);
    }
}
class AA extends A {
    private int a; //its not the same 'a'!!
    public void foo(){ //ok, we override, so we can 'overwrite', but...
        super.foo(); //... what with this?
        System.out.println(a);
    }
}

正如你所看到的,很难实现自动化。如果这个层次结构中的某个类扩展了某个库类,而您没有源代码,该怎么办?所以,合并很难,而且非常非常糟糕,这就是为什么我认为没有人写过这样的工具。

最新更新