Java 带有泛型的CustomLinkedList
我正在使用泛型实现linkedlist。但我在这条线上找到了“多个标记” -MyIterator类型不是泛型;无法参数化 争论不休 " 在return语句中。 图1是一个界面Java 带有泛型的CustomLinkedList,java,generics,Java,Generics,我正在使用泛型实现linkedlist。但我在这条线上找到了“多个标记” -MyIterator类型不是泛型;无法参数化 争论不休 " 在return语句中。 图1是一个界面 public Iterator<Figure> iterator() { class MyIterator implements Iterator<Figure> { private Node current; private MyIterator(Nod
public Iterator<Figure> iterator() {
class MyIterator implements Iterator<Figure> {
private Node current;
private MyIterator(Node n) {
current = n;
}
public boolean hasNext() {
return current.next != null;
}
public Figure next() throws NoSuchElementException {
if (current.next == null)
throw new NoSuchElementException();
current.setNext(current.next);
Object c=current;
return (Figure) c;
}
public void remove() {
throw new UnsupportedOperationException();
}
}
return new MyIterator<Figure>();
}
公共迭代器迭代器(){
类MyIterator实现了迭代器{
专用节点电流;
私有MyIterator(节点n){
电流=n;
}
公共布尔hasNext(){
返回current.next!=null;
}
public Figure next()抛出NoTouchElementException{
if(current.next==null)
抛出新的NoTouchElementException();
当前设置下一步(当前设置下一步);
对象c=当前;
返回(图)c;
}
公共空间删除(){
抛出新的UnsupportedOperationException();
}
}
返回新的MyIterator();
}
显然MyIterator
不是通用的。您已经像泛型类型一样使用了它。将您的返回声明更改为:
return new MyIterator();