Getting rid of an inordinate use of the `instanceof` function I am working with a library that has a base class Base, and three class descending from it Destination, Amenity and Landmarks.
The Base class looks something like this 

public class Base {
    public Integer id;
    public String externalId;

    public Base() {
    }

    public int getId() {
        return this.id;
    }

    public String getExternalId() {
        return this.externalId != null ? this.externalId : "";
    }
}


The children classes look like this 

public class Destination extends Base implements Parcelable {
    private String name;
    private String description;
    private Point[] points

    public String getName() {
        return this.name;
    }

    public String getDescription() {
        return this.description;
    }

    public Point[] getPoints(){
        return this.points;
    }

}


The important thing to note here is that the three child classes have the points property and the getPoints getter for accessing it. If it was my implementation, I would bring the points field into the base class to avoid replicating multiple times in the child classes but like I said, it's a library and I cannot modify the source.
While working with the library I have ran into a situation where I have had to use the instanceof function multiple times and since this is considered a code smell, I'd like to know if there is a better way of going about it. The situation I'm describing happens when I try to get one of the child objects when a point item is specidied, the code looks like this right now

public static &lt;T&gt; T getCurrentMapObjectWithPoint(Point point, T [] bases){

        T base = null;
        for(T model: bases){
            Point[] points = getpointsArrayFromMapObject(model);
            for(Point currentpoint: points){
                if(currentpoint.id.equals(point.id)){
                   return base;
                }
            }
        }
        return base;
    }

    private static &lt;T&gt; point[] getpointsArrayFromMapObject(T base){
        if(base instanceof Amenity ){
            return ((Amenity) base).getpoints();
        } else if(base instanceof Destination){
            return ((Destination) base).getpoints();
        } else if (base instanceof LandMark){
            return ((LandMark) base).getpoints();
        }
        return new point[]{};
    }


So simply put, given a Point and list of map items(T[] base - which means and array of either Amenity, Destination or Landmark) I'm trying to figure out which Amenity, Destination or LandMark the point belongs to which means I have to go throgh the list of map items and for each item, go through the points for that item and whenever the point id is equal to the id of the point given at the start I break out of the loop and return the current map item. Is there a better way of doing this without using instanceof multiple times?
I will assume that you really, really want to use the classes defined in the library and not make your own. Presumably the library classes offer other benefits that were not otherwise relevant to the question.

One thought is that you could define an interface that offers a function with the same signature as getPoints, though with a different function name.

public interface PointListGettable {
    public Point[] getPointList();
}


(You'd probably want to come up with a better name than PointListGettable, however.)

Extend the offending classes so they implement this interface. For example:

public MyDestination extends Destination implements PointListGettable {
    public Point[] getPointList() {
        return getPoints();
    }
}


Now you can implement a function with a signature like

public PointListGettable getCurrentMapObjectWithPoint(Point point, PointListGettable [] bases)


but rather than define a function like your getpointsArrayFromMapObject, within the body of the for(PointListGettable model: bases) loop you can just write model.getPointList().

If it's just a matter of getting around one perceived defect in the inheritance scheme without using instanceof, however, I'm not sure all this is worth it.