所以我有一个AbstractSyntaxTreeNode.java类(这里是它的一部分)
public abstract class ASTreeNode implements Iterable<ASTreeNode>{
protected List<ASTreeNode> children;
protected ASTreeNode(){
children = new LinkedList<ASTreeNode>();
}
protected ASTreeNode(ASTreeNode... children){
this();
for(ASTreeNode c: children)
{
this.addChild(c);
}
然后我有另一个扩展ASTreeNode的类操作
public class Operation extends ASTreeNode
{
char s;
private Operation(Term t)
{
//QUESTION REGARDING THIS PART
super(t, t.getChild(0), t.getChild(1));
}
}
如何将所有对象t(也将ASTreeNode扩展)子进入super ctor参数?没有这样的硬编码?我尝试了super(t,t.children),但构造函数不在参数中使用List,只使用ASTreeNodes 被采取。
哦,这是课程期限
public class Term extends ASTreeNode
{
char symbol;
private Term(Factor f)
{
super(f, f.getChild(0));
}
}
还有更多的课程将他们的孩子送到另一个节点
答案 0 :(得分:1)
在ASTreeNode中添加一个构造函数,它接受一个List作为它的参数。
public abstract class ASTreeNode ... {
public ASTreeNode(List<? extends ASTreeNode> children) {
this.children = children;
}
}
public class Operation extends ASTreeNode {
char s;
private Operation(Term t) {
super(t.getChildren());
this.addChild(t);
}
}