• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

retrieval of different types - typedef?

 
karl holmgren
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic