GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes retrieval of different types - typedef? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "retrieval of different types - typedef?" Watch "retrieval of different types - typedef?" New topic
Author

retrieval of different types - typedef?

karl holmgren
Greenhorn

Joined: Aug 16, 2004
Posts: 4
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?

Thanks!
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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.


There is no emoticon for what I am feeling!
 
GeeCON Prague 2014
 
subject: retrieval of different types - typedef?