This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "retrieval of different types - typedef?" Watch "retrieval of different types - typedef?" New topic

retrieval of different types - typedef?

karl holmgren

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?

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!
I agree. Here's the link:
subject: retrieval of different types - typedef?
jQuery in Action, 3rd edition