我正在实现一个自定义数据结构,它为我提供了一些集合的属性和列表的其他属性。不过,对于大多数已实现的方法,我在 Java 7 上的 IntelliJ IDEA 中收到了这个奇怪的警告:
未注解的方法会覆盖使用@NotNull 注解的方法
编辑:下面的代码与问题无关,而是原始问题的一部分。由于 IntelliJ 中存在错误,因此出现此警告。请参阅(希望)解决您的问题的答案。
我找不到任何相关的东西,我不确定我是否真的错过了某种检查,但我已经查看了 ArrayList 和 List 接口的源代码,但看不到什么这个警告实际上是关于。它在引用列表字段的每个实现的方法上。这是我制作的课程的片段:
public class ListHashSet<T> implements List<T>, Set<T> {
private ArrayList<T> list;
private HashSet<T> set;
/**
* Constructs a new, empty list hash set with the specified initial
* capacity and load factor.
*
* @param initialCapacity the initial capacity of the list hash set
* @param loadFactor the load factor of the list hash set
* @throws IllegalArgumentException if the initial capacity is less
* than zero, or if the load factor is nonpositive
*/
public ListHashSet(int initialCapacity, float loadFactor) {
set = new HashSet<>(initialCapacity, loadFactor);
list = new ArrayList<>(initialCapacity);
}
...
/**
* The Object array representation of this collection
* @return an Object array in insertion order
*/
@Override
public Object[] toArray() { // warning is on this line for the toArray() method
return list.toArray();
}
编辑:我在类中有这些额外的构造函数:
public ListHashSet(int initialCapacity) {
this(initialCapacity, .75f);
}
public ListHashSet() {
this(16, .75f);
}