如何从使用泛型的父抽象类重写方法的方法返回特定类型?

时间:2015-10-30 16:07:21

标签: java generics

我有一个通用树

public abstract class Tree<T extends Term, U extends Terms>{
    protected T           termA;
    protected U           termB;
    protected Tree<T,U>[] childs;

    protected Tree( final T termA, final U termB, final Tree<T,U>[] childs){
        this.termA = termA;
        this.termB = termB;
    }

    public T getTermA(){
        return termA;
    }

    public U getTermB(){
        return termB;
    }

    public Tree<T,U>[] getChilds(){
        return childs;
    }
}


public final class TreeImpl extends Tree<Boolean,String>{
    public TreeImpl( final Boolean termA, final String termB,TreeImpl[] childs){
        super( termA, termB, childs);
    }
}

在这种情况下,TreeImpl.getChilds返回Tree []。我想知道隐藏方法是否为

public TreeImpl[] getChilds(){
        return childs;
}

这是最好的办法吗?

由于

0 个答案:

没有答案