I am writing a program that has 3 specific classes, ImageHandler, TiffHandler, and JPEGHandler.
JPEGHandler and TiffHandler both extend ImageHandler. Inside of all 3 classes is a method called compress() which compresses whatever image the object is currently handling.
I am also trying to create a separate class that implements Runnable, but I don't want to have to create two Runnable classes, one for TiffHandler and one for JPEGHandler. I would rather just create a Runnable class that can accept a ImageHandler object.
My issue is that since the Runnable class only has an ImageHandler object, whenever I call compress() it throws errors during runtime saying that:
Uncompilable source code - compress() in fjimagecompressor.JPEGHandler cannot override compress() in fjimagecompressor.ImageHandler
overridden method does not throw java.io.IOException
The second line confuses me, as inside of ImageHandler I have a blank method called compress():
public void compress() throws IOException{
/*blank*/
}
and inside of TiffHandler and JPEGHandler I also have compress() which throws IOException, except compress() does something different depending on if it is a JPEGHandler or a TiffHandler. I am unsure whether I am simply using polymorphism incorrectly or if I am missing something in my super class ImageHandler. Why is the compiler saying that the super method doesn't throw an IOException when I do indeed declare that it does?
*Handlerclasses, but the problem is that the copy ofImageHandlerthat the runtime sees doesn't have thethrowsclause. Clean and recompile.