• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

retrieval of different types - typedef?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic