This discussion is archived
6 Replies Latest reply: Dec 15, 2012 5:15 AM by Kayaman RSS

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

meandmycode Newbie
Currently Being Moderated
Hi,

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):
                                   |                                 
                                 Node
                                   |
                 ----------------------------------                 
                |
            Linux
                |   
         ---------------------
        |                    |
     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?

br,

//mike

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points