This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have built a data structure, which among other thing contains the following method:
channels is here an array of Vectors.
I would however, also like to store other objects than numbers with Double type wrapper. Storing is no problem. However, how should I perform the retrieval part? It feels like I for starters should be using something corresponding to the typedef command in C++. Is there anything like that in Java?
If you are going to store other types of object in the Vector, you make have to loosen the typing on your method:
... and force the calling code to do a case analysis:
But such code starts to smell bad. Why are you returning disparate objects from retreiveThis? Is there some common type (class or interface) what they might share? What about storing objects in the Vector that in turn may hold values (like double), but include logic for how to use their contents:
In the end, I don't see what this has to do with typedefs (which Java lacks). A better description of you problem will allow forum members to understand the problem better and suggest more targeted solutions.