By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,501 Members | 1,235 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,501 IT Pros & Developers. It's quick & easy.

Polymorphism data type testing

P: 63
If I have a collection of polymorphic objects, is there a way to test exactly what data type an element of that collection is?

Iíve though of two workarounds:

1. Type casting and testing thought exception handling.
2. Adding a String to the root class that represents the data type.

But if there is a conventional way of testing this, I would rather use that.

Iíve tried doing a Google search on polymorphism data type testing, but it didnít turn up anything.
May 7 '07 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
If I have a collection of polymorphic objects, is there a way to test exactly what data type an element of that collection is?

Iíve though of two workarounds:

1. Type casting and testing thought exception handling.
2. Adding a String to the root class that represents the data type.

But if there is a conventional way of testing this, I would rather use that.

Iíve tried doing a Google search on polymorphism data type testing, but it didnít turn up anything.
One of
instanceOf operator
getClass method

should be able to help you.
May 7 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.