[英]Can't instantiate AbstractSet Class
Ok I've been searching for this problem for a while. 好的,我一直在寻找这个问题。 I keep getting an error that I can't instantiate
abstractSet
. 我一直收到一个错误,我无法实例化
abstractSet
。 It keeps asking for a generic. 它不断要求通用。 I add the generic but still no dice.
我添加了通用但仍然没有骰子。
import java.util.AbstractSet;
import java.util.Set;
public class UnorderedTree{
private Object root;
private Set subtrees; //Switched to AbstractSet
private int size;
public UnorderedTree(Object root){
this(root);
subtrees = new AbstractSet(); //ERROR HERE WITH <Object>
size=1;
}
}
Any pointers would help 任何指针都会有所帮助
As its name suggested, AbstractSet is abstract, you can not instantiate it. 顾名思义, AbstractSet是抽象的,你无法实例化它。 as its javadoc said:
正如其javadoc所说:
This class provides a skeletal implementation of the Set interface to minimize the effort required to implement this interface.
此类提供Set接口的骨干实现,以最大限度地减少实现此接口所需的工作量。
You should use some concrete set like HashSet . 你应该使用像HashSet这样的具体集合。
AbstractSet is an "abstract" base class, which cannot be instantiated. AbstractSet是一个“抽象”基类, 无法实例化。 It has a protected constructor which is overridden by the classes that extend this abstract class.
它有一个受保护的构造函数,它被扩展此抽象类的类所覆盖。
Please look at the javadoc for more help. 请查看javadoc获取更多帮助。
Direct known subclasses of this class are: ConcurrentSkipListSet, CopyOnWriteArraySet, EnumSet, HashSet, TreeSet - You are probably interested in one of these. 这个类的直接已知子类是:ConcurrentSkipListSet,CopyOnWriteArraySet,EnumSet,HashSet,TreeSet - 您可能对其中一个感兴趣。
Good luck! 祝好运!
AbstractSet is an abstract class. AbstractSet是一个抽象类。 You can't instantiate abstract classes, because they (generally) don't contain a complete implementation of the type they're defining.
您无法实例化抽象类,因为它们(通常)不包含它们所定义类型的完整实现。 It has nothing to do with generics.
它与泛型无关。
You can't initialize abstract
classes. 您无法初始化
abstract
类。
From Java 6
API this is the definition of the AbstractSet
class. 从
Java 6
API开始,这是AbstractSet
类的定义。
public abstract class AbstractSet<E>
extends AbstractCollection<E>
implements Set<E>
For more information please refer Java API documentation . 有关更多信息,请参阅Java API文档 。
Your can overcome this compilation error by using: 您可以使用以下命令克服此编译错误:
private Set<YourObjType> subtrees = new HashSet<YourObjType>();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.