I have two enums (Enum1 and Enum2) that both implement an interface (Face).
Both enums also have fields (Image img).
The way the interface is implemented is different on each enum.
Then I have a serializable class (Message) that has a field called payload that is a Face.
When i send a Message through a socket which the value of its payload is of Enum1 everything works OK. But when i do the same thing with Enum2 I get a not serializable exception for the image field on that Enum.
There is a bunch of code related to all of this and i know that the mistake could be hidden in it but its a clear Exception so my question is: How does java handle sending interfaced enums through the sockets? What will actually be sent, what will be received, and what can i cast the received payload to?
interface Face {
void action();
}
enum Enum1 implements Face {
AA("aa"), BB("bb"), CC("cc");
Image img;
Enum1(String _path){
// init image
}
void action(){
// do stuff
}
}
enum Enum2 implements Face {
XX("xx"), YY("yy"), ZZ("zz");
Image img;
Enum2(String _path){
// init image
}
void action(){
// do other different stuff
}
}
class Message implements Serializable {
Face face;
Message(Face _face){
this.face = _face;
}
}
socket.send(new Message(Enum1.AA));
// Everything ok
socket.send(new Message(Enum2.XX));
// Not serializable exception (Image)