6 Replies Latest reply on Dec 15, 2012 1:15 PM by Kayaman

    get method returning objects that are sub sub classes of a specific type


      I have the following method:
      List<Node> xNode = nodeManager.getNode(NodeType.X);
      But now we have the following class hierarchy ( Node and Linux are abstract):
              |                    |
           XNode           YNode
      With the above method I am not able to access the methods of the XNode object but only for Node.

      I want to keep the getNode(NodeType type) general so that when I create the nodes of a specific type it returns the child child of Node like XNode or YNode. Then I will be able to access specific operations possible all the way down to XNode.

      Can I use generics here so that I don't return a general node type.
      List<? extends Node> xNode = nodeManager.getNode(NodeType.X);
      Does the list contain nodes of type XNode if getNode(NodeType.X) returns XNode?