James Jefferies and ShedCode Ltd

The world of James and ShedCode

Difference Between Instanceof and isInstance

f  you use instanceof or isInstance it will succeed if the class can be ‘upcast’, so if it inherits from what you’re comparing it to..

1
classA instanceof classB

is true if classA is of a type inherited from classB

1
classA.getClass().isInstance(ClassB.class))

isInstance allows you to do it dynamically though