I have a Node class:
public class Node<T extends MySuperClass> { private T data; private Node<? extends MySuperClass> parent; private List<Node<? extends MySuperClass>> children; public Node(T data, Node<? extends MySuperClass> parent, List<Node<? extends MySuperClass>> children) { this.data = data; this.parent = parent; this.children = children; } public T getData() { return data; } public Node<? extends MySuperClass> getParent() { return parent; } public List<Node<? extends MySuperClass>> getChildren() { return children; } public void setData(T data) { this.data = data; } public void setParent(Node<? extends MySuperClass> parent) { this.parent = parent; } public void setChildren(List<Node<? extends MySuperClass>> children) { this.children = children; } } I need to create a map of Generic Node defined above. I have to write something like this
List<Map<Long, Node<? extends MySuperClass>>> tree = new ArrayList<Map<Long, Node< extends MySuperClass>>>(); When I try to add an instance of map to the list
public MyClass extends MySuperClass{ } Map<Long, Node<MyClass>> myMap = new HashMap<Long,Node<MyClass>>(); tree.add(myMap); The Compiler gives me the following message:
The method add(Map<Long,Node<? extends MySuperClass>>) in the type List<Map<Long,Node<? extends MySuperClass>>> is not applicable for the arguments (Map<Long,Node<MyClass>>) Syntactically it is correct. I Can't understand why it doesn't work.
Map<Long, Node<MyClass>> myMap = new ArrayList<Long,Node<MyClass>>? Write what you really use there.Aon the unrelated objectB).