我想在所述类的方法内调用通用抽象类的构造函数。下面的代码显示了这一点:通用抽象类构造函数
public abstract class Node<T> {
public Collection <Node<T>> pars;
public Collection<Node<T>> interactors;
private boolean target = false;
private boolean multiple = false;
private T value;
//constructor for a simple node
public Node(T val){
this.value = val;
}
//constructor for a multiple interaction node
public Node(Collection<Node<T>> inter, T val){
this.interactors = inter;
this.value = val;
if (inter.size()>0){
this.multiple = true;
}
}
public void find_inters(){
ArrayList<Collection<T>> multi_interactions = search();
for (int i = 0; i < multi_interactions.size(); i++){
Node<T> a = new Node<T>(multi_interactions.get(i), this.value); <----i get compile error here
}
}
}
但我不断收到一个错误,我不能实例化类型节点。我想在函数find_inters()中创建一个新的Node对象,但我不能。任何人都知道为什么/可能的解
如果您需要实例化类型,为什么要使它成为'abstract'? –
简单,因为还有其他方法我不能实现,所以我必须使它们抽象。将删除抽象允许我实例化一个节点? (因为我总是可以找到抽象方法的解决方法) –
是的,但是你不能有未实现的方法。 – zapl