나는 특별한 직렬화 (심지어 과도 객체 직렬화)을 구현하면서 흐름을 알아 내기 위해 노력 해왔다를 사용하지만 흐름을 이해할 수 없다 :자바 실행 논리 동안 사용자 정의 직렬화
public class object1 implements Serializable {
int i = 2032423;
String str = "dssadsadsdfsfsdfczxc";
StringBuilder sb = new StringBuilder();
transient testobject ob1 = new testobject();
String str2;
testobject ob2;
String sooo =new String("jbdskdbshxcbc");
public static void main(String[] args) throws ClassNotFoundException {
try {
FileOutputStream fos = new FileOutputStream(new File(
"serialTst.txt"));
ObjectOutputStream oos = new ObjectOutputStream(fos);
object1 obj1 = new object1();
obj1.ob1.str = "this guy is referred";
oos.writeObject(obj1);
oos.flush();
oos.close();
fos.close();
FileInputStream fis = new FileInputStream("serialTst.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
object1 obb=(object1)ois.readObject();
System.out.println(obb.str2);
ois.close();
fis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void readObject(ObjectInputStream Aois)
throws ClassNotFoundException, IOException {
Aois.defaultReadObject();
str2 = (String) Aois.readObject();
System.out.println(ob1.str);
System.out.println(sooo); // Why Null here??
}
private void writeObject(ObjectOutputStream Aoos) throws IOException {
Aoos.defaultWriteObject();
Aoos.writeObject(ob1.str);
}
}
를 ** 왜 정상적인 (문자열 sooo = "something")이 인쇄 될지라도 String sooo가 null 인 경우 ???? **
object1 클래스의 인스턴스가 생성되지 않으면 어떻게 readObject 및 writeObject가 실행됩니까 ??
@luigi 관심을 가져 주셔서 감사합니다,하지만 귀하의 솔루션은 확실히 작동하지만, 왜 내가 제안한 내가 일하는 법을 알고 싶습니다 ??? –
당신은 당신의 질문이 아니라 내 대답에이 코멘트를 게시 했어야합니다. 또한, 내 이름은 이중 G :)입니다. –