Warning: type E parameter hides type E when using the inner class

I wrote a stack, with static Node and other non-static.

public class Stack<E> implements Iterable<E>
{
    private int N;
    private Node<E> first;

    private static class Node<E>    // This works fine.
    {
        private E item;
        private Node<E> next;
    }
}

But when I try to make Node non-static, it gives me this warning "Type E parameter hides type E"

public class Stack<E> implements Iterable<E>
{
    private int N;
    private Node<E> first;

    private class Node<E>    // This shows warning.
    {
        private E item;
        private Node<E> next;
    }
}

A little understanding, which I am talking about, since the static memeber is a member of the class, so it does not give me a warning, but when I make it non-static, it belongs to the instance. But this is not a clear idea.

+4
source share
1 answer

, E , . Node :

public class Stack<E> implements Iterable<E>
{
    private int N;
    private Node<E> first;

    private class Node<T>
    {
        private T item;
        private Node<T> next;
    }
}

E , ; Node - , (Stack<object>.Node Stack<String>.Node - ):

public class Stack<E> implements Iterable<E>
{
    private int N;
    private Node first;

    private class Node
    {
        private E item;
        private Node next;
    }
}

, , Node , Stack<E>, - E . Node , Stack<E>, , .

+10

All Articles