I have a iterface called A. Now i derive 3 classes from interface A.
How i can i add some method to the interface like getType() which return me the right type of instance I am dealing with. I don’t want to do something like demo instanceOf A in nested if else for checking the instance type.
There’s always
.getClass()which will return the object’sClass. But it is essentially the same asinstanceof. You should not need to know the concrete type. Put the logic in each implementation instead. So for example:instead of: