I've got a file "DefaultIntValue.java" that implements interface
<IIntValue> which is a descendant of <IValue> which requires it to
have <writeObject()> and <readObject()> methods, and four other files
that do similar things except that instead of reading and writing
<int>s they read and write <double>s, <float>s, <long>s and <String>s.
I originally defined the "DefaultIntValue.java" methods like so:
public void writeObject ( ObjectOutputStream isOut)
{
isOut.writeInt( integer);
}
public void readObject ( ObjectInputStream isIn)
{
integer = isIn.readInt();
}
But when I compiled these "DefaultIntValue.java" methods the compiler
told me "Unhandled exception type IOException" for both methods, and
got identical complaints for each of the other four files.
So I went in and changed my methods like so:
public void writeObject ( ObjectOutputStream isOut)
throws IOException
{
isOut.writeInt( integer);
}
public void readObject ( ObjectInputStream isIn)
throws IOException
{
integer = isIn.readInt();
}
and did similar changes to each of the four other files and then com-
piled, and the message the compiler gave me was, "Exception
IOException is not compatible with throws clause in
IValue.writeObject(ObjectOutputStream)" for <writeObject()> and "Ex-
ception IOException is not compatible with throws clause in
IValue.readObject(ObjectInputStream)" for <readObject()>. I got simi-
lar errors for each of the four other files.
Can anyone tell me what these compilation errors mean and what I have
to do to get these files to compile? Any feedback would be greatly
appreciated.
---Kevin Simonson
"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
kvnsmnsn@hotmail.com - 03 Aug 2006 01:21 GMT
If it makes a difference all of this was done using Eclipse.
---Kevin Simonson
"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
jmcgill - 03 Aug 2006 01:27 GMT
> and did similar changes to each of the four other files and then com-
> piled, and the message the compiler gave me was, "Exception
> IOException is not compatible with throws clause in
> IValue.writeObject(ObjectOutputStream)"
You cannot simply add a throws clause to a method that overrides a
method in a superclass.
You need to either put a try block around your call and actually handle
the error, or else you need to add the throws clause to the superclass(es).
kvnsmnsn@hotmail.com - 03 Aug 2006 04:59 GMT
=> and did similar changes to each of the four other files and then
com-
=> piled, and the message the compiler gave me was, "Exception
=> IOException is not compatible with throws clause in
=> IValue.writeObject(ObjectOutputStream)"
=
=You cannot simply add a throws clause to a method that overrides a
=method in a superclass.
=
=You need to either put a try block around your call and actually
=handle the error, or else you need to add the throws clause to the
=superclass(es).
Now I _really_ feel stupid. I'm sure this will fix my problem.
---Kevin Simonson
"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_