In what case must the type parameter of a constructor of a generic class be generic?

Viewed 17

I have the following class and its constructor, and I'm not sure why the IDE says it is a problem: "Incompatible types: found 'T'/'Node', required: 'T'/'Node'. As soon as I remove the type parameter from the constructor signature, however, the warning goes away.

class Node<T>{
        private T element;
        private Node<T> nextNode;

        public <T> Node(T element, Node<T> nextNode){
            this.element = element;
            this.nextNode = nextNode;
        }
    } 

I am wondering what the reason for this is and what is the difference between using a regular constructor (that might accept generic types in its parameters) and a generic constructor.

0 Answers
Related