I have a collection of animals (interface) which contains birds and cats (both also interfaces). I want to print out all the cats to the console and I am forbidden to use
instanceof (I did not make up this arbitrary restriction).
What is the correct way in OOP to solve this?
getClass() is not possible because I just have access to the API and it would not comply with OOP concepts. Another alternative would be the visitor pattern (I can change the API), but this would be just be a very convoluted way to effectively perform a type-check.