And voila! Suddenly the print statement displays “”. In your face, type erasure. Note that we can also use context bound syntax here:
Important note: My proposed solution is by no means pretty but I think it answers the question. In my opinion something is already seriously flawed from an OO point of view in the presented code (e.g. use of reflection) and a better solution would have to start by changing the underlying data structures. But that can only be done if we have more information how this is to be used, e.g. what kind of logic consumes the returned list.
The subprogram is said to be generic. The subprogram specification is preceded by the generic formal part consisting of the reserved word followed by a list of generic formal parameters which may be empty. The entities declared as generic are not directly usable, it is necessary to instantiate them.Similarly, generic packages can be used, for example, to implement a stack of any kind of elements:
Even after your edit(s) it is not entirely clear what you are trying to achieve but here are my assumptions: -You want to have some kind of Node object that acts as a container for different types of NodeData elements. -You want to be able to return list from this Node object that contains all NodeData elements stored in the Node container, regardless of the NodeData objects' type.