Name: gm110360 Date: 08/25/2004
A DESCRIPTION OF THE REQUEST :
class G1<T> implements Serializable {}
class G2<T> implements Serializable
{
protected G1<T> g1_instance;
private void readObject(ObjectInputStream in) throws IOException
{
try {
g1_instance = (G1<T>) in.readObject();
} catch (ClassCastException e) {}
} catch (ClassNotFoundException e) {}
}
}
This gives a compiler warning, as specified in the generics tutorial. However,
the implications are that no class containing a generic type may specialize
the serializablity mechanism without a warning.
JUSTIFICATION :
Since serialization is an often used language feature, and one hopes that generics will be as well, it would be nice if one could use the two mechanisms together without compiler warnings.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I'm not a generics expert, but perhaps adding a generic method to ObjectInputStream
<T> T readGeneric()
would help with this.
ACTUAL -
A compiler warning is issued using two standard language mechanisms together.
---------- BEGIN SOURCE ----------
import java.io.Serializable;
import java.io.IOException;
class G1<T> implements Serializable {}
class G2<T> implements Serializable
{
protected G1<T> g1_instance;
private void readObject(ObjectInputStream in) throws IOException
{
try {
g1_instance = (G1<T>) in.readObject();
} catch (ClassCastException e) {}
} catch (ClassNotFoundException e) {}
}
}
---------- END SOURCE ----------
(Incident Review ID: 297700)
======================================================================