Posted By:
Eelco_Cramer
Posted On:
Friday, September 7, 2001 06:52 AM
I have a small problem, when an object is returned from a hashtable I don't now the objectype @ compiletime. What I could do is something like: HashTable hash = ... ... Object theObject = Hashtable.get("theKey"); if (theObject.getClass().getName().compareTo("Ljava.lang.String")) { theString = (String)theObject; } else if ( ... ... } else { System.out.println("BOOO, I didn't program the correct object type!"); } Does anyone know a more generic solution? I like to cast the object at runtime! Cheers, Eelco
More>>
I have a small problem, when an object is returned from a hashtable I don't now the objectype @ compiletime. What I could do is something like:
HashTable hash = ...
...
Object theObject = Hashtable.get("theKey");
if (theObject.getClass().getName().compareTo("Ljava.lang.String")) {
theString = (String)theObject;
}
else if ( ...
...
}
else {
System.out.println("BOOO, I didn't program the correct object type!");
}
Does anyone know a more generic solution? I like to cast the object at runtime!
Cheers,
Eelco
<<Less