Hi
I created a class named ID3Frame, and it has some subclass, such as ID3TextFrame and ID3ImageFrame. One of the methods that need to be implemented (or extended) in each subclass is the "getFrameValue" method.
Now here's my problem: when a ID3TextFrame object is used, the getFrameValue should return a String, but when an ID3ImageFrame is used, it should return an Image.
I know i can just extend the ID3Frame class, and add the method, but then i have to cast each ID3Frame object (i have a HashMap where i store ID3Frame objects in) to the specified subclass before calling methods (cause the getFrameValue is not defined in the ID3Frame class). When i use an abstract ID3Frame class, i can only return an Object, and the same goes for an interface.
At the moment these are my classes:
Java Code:
public abstract class ID3Frame {
public abstract Object getFrameValue
();
}
public class ID3ImageFrame extends ID3Frame {
public Image getID3FrameValue
(){ }
}
public class ID3TextFrame extends ID3Frame {
public String getFrameValue
(){ }
}
this works, but then i always get an Object as return type, and not the correct one
So my question is: is there a way to specify the method in the ID3Frame class, with the method returning an Image, String or Integer object depending on the subclass?
I hope i explained it well enough, if not let me know, i'll give it another try