我得到了不兼容的类型:对象无法转换为 T,其中 T 是类型变量:T 扩展了类 Stack 中声明的对象。
你能帮忙吗,我不知道为什么会这样,方法 pop() 和 getData() 是相同的类型 T ...
这是缩短的代码。
public class Stack<T> {
Node head;
public T pop() {
return head.getData(); //the error is on this line
}
private class Node <T> {
private final T data;
private Node next;
private Node(T data, Node next) {
this.data=data;
this.next=next;
}
private T getData() {
return data;
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14399 次 |
| 最近记录: |