I have an Object in java. Is there a way to check if an object is an instance of a String, HashMap, or HashMap[ ] before actually casting it to those objects?
If not, as it seems counterintuitive that the above would work, is there a way to cast it into each object, and test something about the newly casted object to see if its in fact the type of object into which it was casted?
Yes:
By the way, to clarify regarding this:
You cannot cast something into an invalid type. If
objhas typeString, then((Integer)obj)will cause aClassCastExceptionto be raised at run-time.