我沒有張貼的全部代碼。我有這樣的:一般使用與內部類的問題
public class LinkedList2<T extends Comparable<T>> implements Iterable<T> {
private Node<T> head;
private Node<T> tail;
private int numOfElem;
private class Node<T> {
Node<T> next;
T data;
Node(Node<T> next, T data) {
this.next = next;
this.data = data;
}
}
private class LinkedList2Iterator<T> implements Iterator<T> {
private int count = LinkedList2.this.numOfElem;
private Node<T> current = LinkedList2.this.head;
}
}
在javac -Xlint LinkedList2.java
我得到這個錯誤:
LinkedList2.java:134: incompatible types
found : LinkedList2<T>.Node<T>
required: LinkedList2<T>.Node<T>
private Node<T> current = LinkedList2.this.head;
^
1 error
你能幫忙嗎?
可能重複( http://stackoverflow.com/questions/8512627/java-generics-type-parameter-hiding)和[類型混亂定製的Java迭代器(http://stackoverflow.com/questions/1290611/custom-java-iterator-帶型混淆) –