Glass comparison via getClass
To compare 2 object's that are created externally to my program but must be from the same class to be used within my program, would the following code be an accurate way of doing it?
if (rootNode !=null && ! item.getClass().equals(rootNode.listFront.mItem.getClass()))
{
thrownew IllegalArgumentException("Error: Can not add more than " +
"one object type to this Data Structure");
}
[665 byte] By [
Cavarksa] at [2007-11-27 4:31:21]

Possibly. That code would allow subclasses to slip through. If that's undesirable, you can use the method Class.isAssignableFrom(Class) - the javadocs has it all. I'd also actually consider more null checking, since item may be null, as may be rootNode.listFront and rootNode.listFront.mItem
Is throwing an exception what you want to do here? Not saying it's not, just saying that it's an assumption to be challenged
yep, sub's are fine, and i should have posted more of the method as i am checkin for null above. So that being said, i think it's ok then. The exception is being handled else where.
Still on a large learning curve with java, and wasn't sure this was the best way. But by what you say, then i think it's fine.
Thanks for the fast reply..