2
Reply

Casting with a Hashtable

subscribe

subscribe

Mar 23 2005 7:12 AM
5.1k
Hi all. I´ve a problem. I´ve a hashTable that contains some objects. This objects aren´t of the same class, have different types. When I get an object: myObject = hashTable ["myKey"]; the type of myObject is "Object". This way I cant invoke myObject´s methods. myObject.sayHello() -> Compile Error! I have to cast myObject to (myClass); myObject = (myClass) hashTable ["myKey"]; but I dont know what is myClass at compiling time. Can I do somethig similar to?: myObject = (myObject.getType()) hashTable ["myKey"]; Sorry, but my english is too poor. And Thanks!!!

Answers (2)