I have a method in my Android app that can either display from a List
of Drawables
or Strings
(representing the image URLs).
I tried to make two constructors but got the type erasure error. Now I am using a generic argument and check a member for being a String to represent the URL, like so. In the alternate case I assume that it will be a List of Drawables. Something like this:
setImages(List<?> images) {
this.images = images;
if (String.class.isInstance(images.get(0) ) ) {
isImageUrl = true;
}
}
Is there a way to do this better, somehow preserve type safety ?