Simple list of vectors

1

I'm trying to create a simply linked list in which each node is a vector of type Image , this is the method I'm using to add the new node but the third line as the penultimate throw me the following error:

  

"can not infer type arguments for Node < >"

public void Add(E[] Element) {
    if (this.first == null) {
        this.first = new Node<>(Element);
    } else {
        Node<E> aux = first;
        while (aux.hasNext()) {
            aux = aux.getNext();
        }
        aux.setNext(new Node<>(Element));
    }

}
    
asked by Lorenzo Zuluaga 22.05.2016 в 21:09
source

1 answer

2

You need to specify the type of Node. In your example, the type of Node is E. Your method is like this:

public void Add(E[] Element) {
    if (this.first == null) {
        this.first = new Node<E>(Element);
    } else {
        Node<E> aux = first;
        while (aux.hasNext()) {
            aux = aux.getNext();
        }
        aux.setNext(new Node<E>(Element));
    }
}
    
answered by 23.05.2016 в 13:53