我有这段代码:
public class ListCollection<T> implements Iterable<T> {
private int size;
private ListNode<T> first;
private ListNode<T> last;
...
private class ListNode<E> {
private ListNode<E> next;
private ListNode<E> previous;
private E value;
public ListNode() {
super();
}
}
private class ListIterator<T> implements Iterator<T> {
ListNode<T> next, previous;
public ListIterator() {
next = first;
}
我想初始化迭代器。在 next = first 行中,我收到错误消息。
Type mismatch: cannot convert from ListCollection.ListNode to ListCollection.ListNode
为什么?我该如何纠正这个问题?
最佳答案
改变
private class ListIterator<T> implements Iterator<T>
到
private class ListIterator implements Iterator<T>
否则ListIterator<T>
使用的类型参数T不会与 ListCollection<T>
中声明的类型参数 T 相同.
关于java - 类型不匹配 : cannot convert from "sth" to "sth",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34174475/