譬如有这么一个类interface ITreeNode{
public ITreeNode getParent(){return parent;}
public List getSons() {return sons;}
}现在的问题是:如果有个类RealTreeNode从它继承,结果一定是这样:class RealTreeNode implements ITreeNode{
List sons;
RealTreeNode parent;
public ITreeNode getParent(){return parent;}
public List getSons() {return sons;}
}我希望能是这样:class RealTreeNode implement ITreeNode{
List sons;
RealTreeNode parent;
public RealTreeNode getParent(){return parent;}
public List getSons() {return sons;}
}换句话说,我希望写这样的类的抽象,即包含两个方法getParent和getSons,它们返回[b]该类自身[/b]和[b]List<该类自身>[/b]。应该如何写?
3 回答
富国沪深
TA贡献1790条经验 获得超9个赞
你试试这个,不知道行不
public abstract class ITreeNode { List sons; ITreeNode parent;ITreeNode(List<ITreeNode> sons, ITreeNode parent) { this.sons = sons; this.parent = parent; } public abstract T getParent(); public abstract List<T> getSons(); }
添加回答
举报
0/150
提交
取消