Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

collections : the Object is not enough

Status
Not open for further replies.

tyris

Programmer
Nov 2, 2000
311
FR
i have noticed something about collections, and i'd like to know if it's normal, and what can i do to avoid this.

i do have a Database object (from lotus.domino.* package)

i made a Hashtable "h" containing Database objects.

it seems that when i try to get back Database objects, the h.get(aKey) returns me a Object, not a Database object.

Is it always the same with collections ? do they transform all input in a simple object ? what can i do to keep a Database collection, and not a simple Object collection ? (i'd like to avoid a Database cast)
Best regards,
Elise, XML learning girl X-)
 
It returns an Object reference, it is still of the type that you originally added to the Collection or Map. You are going to have to perform the cast unless you want to write your own Data Structure. What would be the point of that? The Collection API is designed this way so that it is very flexible, the Architects had no way of knowing what type of object you would want to add to the Collections so they accept an Object reference. Since every object in Java must have Object as an Ancestor, this allow a Collection to store an Java object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top