5 Replies Latest reply: Apr 8, 2010 5:24 PM by EJP RSS

    Removing need for cast with generic possible?

    843793
      Hi,

      I've had success with generics in some areas, but not this and wondered if and how you can remove the need to cast in the following example:
      public abstract class Record {
           private String description = "Some Description";
           public String getDescription() {
                return description;
           }
      }
      
      public abstract class RecordDiskFile extends Record { 
           private String imagePath = "Some Image Path";     
           public String getImagePath() {
                return imagePath;
           }
      }
      
      public class Item extends RecordDiskFile {
      }
      
      Record item = new Item();
      item.getDescription();    ----> works
      item.getImagePath();     -----> fails and needs ((RecordDiskFile) item).getImagePath();
      Thanks, Len