I am overriding the addItem() function of an array collection and I would like to detect if the added item implements a particular interface.
Previously I used the, is
operator to detect the class type, but now that I am using an interface for classes I would rather test to see if the object implements the interface.
I expect I could just try and cast the object as the interface and see if it's not null
. Is this the best way to do it?
I could also just create a new addFunction()
that only accepts objects of the interface type.