尝试编写一个返回 Pair 的迭代器:我的 PairIterator 的一部分
public Pair next() {
this.counter ++;
Pair p = new Pair(this.l.get(counter - 1), this.l.get(counter));
//error occurs here
}
public class Pair<E> {
private E e1;
private E e2;
public Pair(E e1, E e2) {
this.e1 = e1;
this.e2 = e2;
}
public E first() {
return this.e1;
}
public E second() {
return this.e2;
}
}
Run Code Online (Sandbox Code Playgroud)
得到
无法实例化类型 Pair
...虽然 Pair 不是抽象类/接口。为什么会发生这种情况?