Ok my fault, my meaning was :
A inner class can not be serialized (ad deserialized) because a no static inner calss can not have static members (and for serilize a class needs a public static final long verionUI).The code below argue this.
public class SerilizeInnerClass {
private final
String fileName = "out.buff";
public SerilizeInnerClass() {
System.out.println("Serialize start");
serialize();
System.out.println("Serialize end");
// System.out.println("Deserialize start");
// deserialize();
// System.out.println("Deserialize end");
}
public static void main (String args []) {
new SerilizeInnerClass();
}
private class Inner implements Serializable {
int i = 10;
public void print() {
System.out.println();
}
}
private boolean serialize() {
boolean ret = false;
Inner inner = new Inner();
FileOutputStream fo = null;
BufferedOutputStream oBuff = null;
ObjectOutputStream oo = null;
try {
fo = new FileOutputStream(fileName);
oBuff =new BufferedOutputStream(fo);
oo = new ObjectOutputStream(oBuff);
oo.writeObject(inner);
fo.close();
oBuff.close();
oo.close();
} catch (IOException ioEx) {
ioEx.printStackTrace();
}
fo = null;
oBuff = null;
oo = null;
ret = true;
return ret;
}
private void deserialize() {
FileInputStream fi = null;
BufferedInputStream iBuff = null;
ObjectInputStream oi = null;
try {
fi = new FileInputStream(fileName);
iBuff = new BufferedInputStream(fi);
oi = new ObjectInputStream(iBuff);
Object get = oi.readObject();
fi.close();
iBuff.close();
oi.close();
} catch (IOException ioEx) {
ioEx.printStackTrace();
} catch (ClassNotFoundException cnfEx) {
cnfEx.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
fi = null;
iBuff = null;
oi = null;
}
}
The code can be compiled but on run time an java.lang.UnsupportedClassVersionError raise.
As far as I know ,there is a way to trick this but this make your code hard to undestand.
And the question remains :
The non static inner classes can be serialized ? If yes how ?