incompatible types : java.lang.Object cannot be converted to T

前端 未结 4 2000
心在旅途
心在旅途 2021-01-14 15:57

Here is my code:

package datastructures;

import java.util.Iterator;

public class Stack{
    private class Node{
        T data;
        N         


        
4条回答
  •  臣服心动
    2021-01-14 16:49

    When you declare Node as

    private class Node
    

    you're declaring a generic type with another T as the T in the enclosing type. You're hiding T. So, in short, it's as if you were declaring it as

    private class Node
    

    Just use

    private class Node
    

提交回复
热议问题