I have an object obj and a class name MyClass, i can check whether obj is of the type MyClass using either instanceof or i can say obj.getClass().equals(“MyClass”).
So i want to know are there any other ways of checking the type of an object.
I have an object obj and a class name MyClass , i can check
Share
Beware:
instanceofreturns true also if your object is a subclass ofMyClass, or if it implements the interface (this is usually what you are interested in – if you recall the “IS A” OOP concept)See also this about
Class.isAssignableFrom(), similar toinstanceofbut a little more powerful.